1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Framework\Containers; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Spl\DataStructures\SplArrayObject; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Config |
22
|
|
|
* |
23
|
|
|
* @package O2System\Framework\Containers |
24
|
|
|
*/ |
25
|
|
|
class Config extends Environment |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Config::loadFile |
29
|
|
|
* |
30
|
|
|
* @param string $offset |
31
|
|
|
* @param bool $return |
32
|
|
|
* |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function loadFile($offset, $return = false) |
36
|
|
|
{ |
37
|
|
|
$basename = pathinfo($offset, PATHINFO_BASENAME); |
38
|
|
|
$filename = studlycase($basename); |
39
|
|
|
|
40
|
|
|
$configFile = str_replace($basename, $filename, $offset); |
41
|
|
|
$offset = camelcase($basename); |
42
|
|
|
|
43
|
|
|
$configDirs = [ |
44
|
|
|
PATH_FRAMEWORK . 'Config' . DIRECTORY_SEPARATOR, |
45
|
|
|
PATH_APP . 'Config' . DIRECTORY_SEPARATOR, |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
if(null !== o2system()->modules) { |
49
|
|
|
$configDirs = modules()->getDirs('Config', true); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
foreach ($configDirs as $configDir) { |
53
|
|
|
if (is_file( |
54
|
|
|
$filePath = $configDir . ucfirst( |
55
|
|
|
strtolower(ENVIRONMENT) |
|
|
|
|
56
|
|
|
) . DIRECTORY_SEPARATOR . $configFile . '.php' |
57
|
|
|
)) { |
58
|
|
|
include($filePath); |
59
|
|
|
} elseif (is_file($filePath = $configDir . DIRECTORY_SEPARATOR . $configFile . '.php')) { |
60
|
|
|
include($filePath); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (isset($$offset)) { |
65
|
|
|
$this->addItem($offset, $$offset); |
66
|
|
|
|
67
|
|
|
unset($$offset); |
68
|
|
|
|
69
|
|
|
if ($return) { |
70
|
|
|
return $this->getItem($offset); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return true; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// ------------------------------------------------------------------------ |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Config::addItem |
83
|
|
|
* |
84
|
|
|
* Adds config item. |
85
|
|
|
* |
86
|
|
|
* @param string $offset |
87
|
|
|
* @param mixed $value |
88
|
|
|
*/ |
89
|
|
|
public function addItem($offset, $value) |
90
|
|
|
{ |
91
|
|
|
$this->offsetSet($offset, $value); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// ------------------------------------------------------------------------ |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Config::getItem |
98
|
|
|
* |
99
|
|
|
* Gets config item. |
100
|
|
|
* |
101
|
|
|
* @param string $offset |
102
|
|
|
* |
103
|
|
|
* @return mixed|\O2System\Spl\DataStructures\SplArrayObject |
104
|
|
|
*/ |
105
|
|
|
public function &getItem($offset) |
106
|
|
|
{ |
107
|
|
|
$item = parent::offsetGet($offset); |
108
|
|
|
|
109
|
|
|
if (is_array($item)) { |
110
|
|
|
if (is_string(key($item))) { |
111
|
|
|
$item = new SplArrayObject($item); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $item; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// ------------------------------------------------------------------------ |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Config::setItem |
122
|
|
|
* |
123
|
|
|
* Sets config item. |
124
|
|
|
* |
125
|
|
|
* @param string $offset |
126
|
|
|
* @param mixed $value |
127
|
|
|
*/ |
128
|
|
|
public function setItem($offset, $value) |
129
|
|
|
{ |
130
|
|
|
$this->offsetSet($offset, $value); |
131
|
|
|
} |
132
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.