-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.php
More file actions
80 lines (62 loc) · 1.2 KB
/
Parser.php
File metadata and controls
80 lines (62 loc) · 1.2 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace JayChow\ConfigParser;
class Parser
{
private $_boolBank = array(
'yes' => true,
'y' => true,
'1' => true,
'true' => true,
'on' => true,
'no' => false,
'n' => false,
'0' => false,
'false' => false,
'off' => false
);
public function load($file)
{
$fh = fopen($file, "r");
if($fh) {
while (($line = fgets($fh)) !== false){
$this->_processLine($line);
}
fclose($fh);
} else {
error_log("Unable to open file");
}
//print_r($this);
}
private function _processLine($line){
//if line is blank skip the line
if(preg_match("/^\s*$/m",$line)){
return;
}
//if line is comment skip the line
if(preg_match("/^\#/m",$line)){
return;
}
$this->_loadConfig(explode("=", $line));
}
private function _loadConfig($arr){
if(sizeof($arr) != 2){
return;
}
$key = trim($arr[0]);
$val = trim($arr[1]);
//Check to see if it's a valid boolean value
if(array_key_exists ($val, $this->_boolBank)){
$val = $this->_boolBank[$val];
}
//Check to see if it's numeric
if(is_numeric($val)){
if(is_float($val)){
$val = (float) $val;
}
if(is_int($val)){
$val = (int) $val;
}
}
$this->$key = $val;
}
}