-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidateConfigHasNoEmptyStrings.class.php
More file actions
44 lines (36 loc) · 1.14 KB
/
ValidateConfigHasNoEmptyStrings.class.php
File metadata and controls
44 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
final class ValidateConfig
{
function construct() {
}
public function validate($config, $requiredKeys) {
$this->traverseKeys($config, $requiredKeys);
}
private function traverseKeys($config, $requiredKeys) {
foreach($requiredKeys as $key) {
#if the value is a string it must be a key. We need to
#check the config for this key and see if it is a none empty string
if (is_scalar($key)) {
echo $key;
$this->checkNonEmptyString($config[$key]);
} elseif (is_array($key)) {
#if the value is an array we need to traverse it looking for string keys
$keys = $key[1];
$this->traverseKeys($config[$key[0]], $keys);
}
}
return;
}
private function checkNonEmptyString($str) {
if (!is_string($str)) {
echo " Not a string " . var_dump($str, true) . "\n";
return;
}
if (empty($str)) {
echo " Empty string.\n";
return;
}
echo " A valid string $str.\n";
return;
}
}