1 | <?php |
||
26 | class ConfigReader { |
||
27 | |||
28 | /** @var array Associative array ($key => $value) */ |
||
29 | protected $cache = []; |
||
30 | |||
31 | /** |
||
32 | * @var OccRunner $occRunner |
||
33 | */ |
||
34 | protected $occRunner; |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * @param OccRunner $occRunner |
||
39 | */ |
||
40 | 1 | public function __construct(OccRunner $occRunner){ |
|
41 | 1 | $this->occRunner = $occRunner; |
|
42 | 1 | } |
|
43 | |||
44 | 1 | public function init(){ |
|
45 | 1 | $this->load(); |
|
46 | 1 | } |
|
47 | |||
48 | /** |
||
49 | * Get a value from OC config by |
||
50 | * path key1.key2.key3 |
||
51 | * @param string $path |
||
52 | * @return mixed |
||
53 | */ |
||
54 | 1 | public function getByPath($path){ |
|
55 | 1 | return $this->get(explode('.', $path)); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Get a value from OC config by keys |
||
60 | * @param array $keys |
||
61 | * @return mixed |
||
62 | */ |
||
63 | 1 | public function get($keys){ |
|
64 | 1 | $config = $this->cache; |
|
65 | do { |
||
66 | 1 | $key = array_shift($keys); |
|
67 | 1 | if (!count($keys)>0 && !is_array($config)){ |
|
68 | return; |
||
69 | } |
||
70 | 1 | if (!array_key_exists($key, $config)){ |
|
71 | return; |
||
72 | } |
||
73 | 1 | $config = $config[$key]; |
|
74 | 1 | } while ($keys); |
|
|
|||
75 | 1 | return $config; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get OC Edition |
||
80 | * @return string |
||
81 | * @throws ProcessFailedException |
||
82 | */ |
||
83 | public function getEdition(){ |
||
87 | |||
88 | /** |
||
89 | * Export OC config as JSON and parse it into the cache |
||
90 | * @throws ProcessFailedException |
||
91 | * @throws \UnexpectedValueException |
||
92 | */ |
||
93 | 1 | private function load(){ |
|
96 | |||
97 | } |
||
98 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.