Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/env/PhabricatorConfigLocalSource.php
12241 views
1
<?php
2
3
final class PhabricatorConfigLocalSource extends PhabricatorConfigProxySource {
4
5
public function __construct() {
6
$config = $this->loadConfig();
7
$this->setSource(new PhabricatorConfigDictionarySource($config));
8
}
9
10
public function setKeys(array $keys) {
11
$result = parent::setKeys($keys);
12
$this->saveConfig();
13
return $result;
14
}
15
16
public function deleteKeys(array $keys) {
17
$result = parent::deleteKeys($keys);
18
$this->saveConfig();
19
return parent::deleteKeys($keys);
20
}
21
22
private function loadConfig() {
23
$path = $this->getConfigPath();
24
25
if (!Filesystem::pathExists($path)) {
26
return array();
27
}
28
29
try {
30
$data = Filesystem::readFile($path);
31
} catch (FilesystemException $ex) {
32
throw new PhutilProxyException(
33
pht(
34
'Configuration file "%s" exists, but could not be read.',
35
$path),
36
$ex);
37
}
38
39
try {
40
$result = phutil_json_decode($data);
41
} catch (PhutilJSONParserException $ex) {
42
throw new PhutilProxyException(
43
pht(
44
'Configuration file "%s" exists and is readable, but the content '.
45
'is not valid JSON. You may have edited this file manually and '.
46
'introduced a syntax error by mistake. Correct the file syntax '.
47
'to continue.',
48
$path),
49
$ex);
50
}
51
52
return $result;
53
}
54
55
private function saveConfig() {
56
$config = $this->getSource()->getAllKeys();
57
$json = new PhutilJSON();
58
$data = $json->encodeFormatted($config);
59
Filesystem::writeFile($this->getConfigPath(), $data);
60
}
61
62
private function getConfigPath() {
63
$root = dirname(phutil_get_library_root('phabricator'));
64
$path = $root.'/conf/local/local.json';
65
return $path;
66
}
67
68
public function getReadablePath() {
69
$path = $this->getConfigPath();
70
return Filesystem::readablePath($path);
71
}
72
73
}
74
75