-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSetting.php
More file actions
77 lines (60 loc) · 1.41 KB
/
Copy pathAppSetting.php
File metadata and controls
77 lines (60 loc) · 1.41 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
<?php
class AppSetting {
private $_model;
private $_searchKey;
private $_value;
private $_type;
private $_id;
public function __construct(ConfigModel $model, $searchKey) {
$this->_model = $model;
$this->_searchKey = $searchKey;
$matches = $this->find();
if(count($matches)>1) {
$this->_value = $matches;
$this->_type = 'array';
$this->_id = null;
} else {
$this->retrieve();
}
}
private function retrieve() {
$value = null;
foreach($this->_model->getRawData() as $i => $data) {
if($this->_searchKey == $data["key"]) {
$this->_value = $data["value"];
$this->_id = $data["id"];
$this->_type = $data["stype"];
break;
}
}
}
private function find() {
$matches = array();
foreach($this->_model->getModeledData() as $keyIndex => $value) {
if(preg_match('/^'.$this->_searchKey.'/', $keyIndex)) {
$matches[$keyIndex] = $value;
$matches = ConfigUtils::buildArray($matches);
}
}
if(!empty($matches)) {
$e = array_filter(explode($this->_model->getDelimeter(), $this->_searchKey));
for($n = 0; $n < count($e) - 1; $n++) {
$matches = array_shift($matches);
}
$matches = $matches[end($e)];
} else {
$matches = array();
}
return $matches;
}
public function getValue() {
return $this->_value;
}
public function getId() {
return $this->_id;
}
public function getType() {
return $this->_type;
}
}
?>