forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorConfigLocalSource.php
50 lines (41 loc) · 1.18 KB
/
PhabricatorConfigLocalSource.php
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
<?php
final class PhabricatorConfigLocalSource extends PhabricatorConfigProxySource {
public function __construct() {
$config = $this->loadConfig();
$this->setSource(new PhabricatorConfigDictionarySource($config));
}
public function setKeys(array $keys) {
$result = parent::setKeys($keys);
$this->saveConfig();
return $result;
}
public function deleteKeys(array $keys) {
$result = parent::deleteKeys($keys);
$this->saveConfig();
return parent::deleteKeys($keys);
}
private function loadConfig() {
$path = $this->getConfigPath();
if (@file_exists($path)) {
$data = @file_get_contents($path);
if ($data) {
$data = json_decode($data, true);
if (is_array($data)) {
return $data;
}
}
}
return array();
}
private function saveConfig() {
$config = $this->getSource()->getAllKeys();
$json = new PhutilJSON();
$data = $json->encodeFormatted($config);
Filesystem::writeFile($this->getConfigPath(), $data);
}
private function getConfigPath() {
$root = dirname(phutil_get_library_root('phabricator'));
$path = $root.'/conf/local/local.json';
return $path;
}
}