Path: blob/master/src/infrastructure/env/PhabricatorConfigLocalSource.php
12241 views
<?php12final class PhabricatorConfigLocalSource extends PhabricatorConfigProxySource {34public function __construct() {5$config = $this->loadConfig();6$this->setSource(new PhabricatorConfigDictionarySource($config));7}89public function setKeys(array $keys) {10$result = parent::setKeys($keys);11$this->saveConfig();12return $result;13}1415public function deleteKeys(array $keys) {16$result = parent::deleteKeys($keys);17$this->saveConfig();18return parent::deleteKeys($keys);19}2021private function loadConfig() {22$path = $this->getConfigPath();2324if (!Filesystem::pathExists($path)) {25return array();26}2728try {29$data = Filesystem::readFile($path);30} catch (FilesystemException $ex) {31throw new PhutilProxyException(32pht(33'Configuration file "%s" exists, but could not be read.',34$path),35$ex);36}3738try {39$result = phutil_json_decode($data);40} catch (PhutilJSONParserException $ex) {41throw new PhutilProxyException(42pht(43'Configuration file "%s" exists and is readable, but the content '.44'is not valid JSON. You may have edited this file manually and '.45'introduced a syntax error by mistake. Correct the file syntax '.46'to continue.',47$path),48$ex);49}5051return $result;52}5354private function saveConfig() {55$config = $this->getSource()->getAllKeys();56$json = new PhutilJSON();57$data = $json->encodeFormatted($config);58Filesystem::writeFile($this->getConfigPath(), $data);59}6061private function getConfigPath() {62$root = dirname(phutil_get_library_root('phabricator'));63$path = $root.'/conf/local/local.json';64return $path;65}6667public function getReadablePath() {68$path = $this->getConfigPath();69return Filesystem::readablePath($path);70}7172}737475