1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Victor Dubiniuk <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Owncloud\Updater\Utils; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class ConfigReader |
26
|
|
|
* |
27
|
|
|
* @package Owncloud\Updater\Utils |
28
|
|
|
*/ |
29
|
|
|
class ConfigReader { |
30
|
|
|
|
31
|
|
|
/** @var array Associative array ($key => $value) */ |
32
|
|
|
protected $cache = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var OccRunner $occRunner |
36
|
|
|
*/ |
37
|
|
|
protected $occRunner; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
protected $isLoaded = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @param OccRunner $occRunner |
47
|
|
|
*/ |
48
|
1 |
|
public function __construct(OccRunner $occRunner){ |
49
|
1 |
|
$this->occRunner = $occRunner; |
50
|
1 |
|
} |
51
|
|
|
|
52
|
1 |
|
public function init(){ |
53
|
1 |
|
$this->load(); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function getIsLoaded(){ |
60
|
|
|
return $this->isLoaded; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get a value from OC config by |
65
|
|
|
* path key1.key2.key3 |
66
|
|
|
* @param string $path |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
1 |
|
public function getByPath($path){ |
70
|
1 |
|
return $this->get(explode('.', $path)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get a value from OC config by keys |
75
|
|
|
* @param array $keys |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
1 |
|
public function get($keys){ |
79
|
1 |
|
$config = $this->cache; |
80
|
|
|
do { |
81
|
1 |
|
$key = array_shift($keys); |
82
|
1 |
|
if (!count($keys)>0 && !is_array($config)){ |
83
|
|
|
return null; |
84
|
|
|
} |
85
|
1 |
|
if (!array_key_exists($key, $config)){ |
86
|
|
|
return null; |
87
|
|
|
} |
88
|
1 |
|
$config = $config[$key]; |
89
|
1 |
|
} while ($keys); |
|
|
|
|
90
|
1 |
|
return $config; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get OC Edition |
95
|
|
|
* @return string |
96
|
|
|
* @throws \Symfony\Component\Process\Exception\ProcessFailedException |
97
|
|
|
*/ |
98
|
|
|
public function getEdition(){ |
99
|
|
|
$response = $this->occRunner->runJson('status'); |
100
|
|
|
return $response['edition']; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Export OC config as JSON and parse it into the cache |
105
|
|
|
* @throws \Symfony\Component\Process\Exception\ProcessFailedException |
106
|
|
|
* @throws \UnexpectedValueException |
107
|
|
|
*/ |
108
|
1 |
|
private function load(){ |
109
|
1 |
|
$this->cache = $this->occRunner->runJson('config:list', ['--private']); |
110
|
1 |
|
$this->isLoaded = true; |
111
|
1 |
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
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.