Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
1.9 kB · 75 lines
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576<?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 (!Filesystem::pathExists($path)) { return array(); }
try { $data = Filesystem::readFile($path); } catch (FilesystemException $ex) { throw new Exception( pht( 'Configuration file "%s" exists, but could not be read.', $path), 0, $ex); }
try { $result = phutil_json_decode($data); } catch (PhutilJSONParserException $ex) { throw new Exception( pht( 'Configuration file "%s" exists and is readable, but the content '. 'is not valid JSON. You may have edited this file manually and '. 'introduced a syntax error by mistake. Correct the file syntax '. 'to continue.', $path), 0, $ex); }
return $result; }
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; }
public function getReadablePath() { $path = $this->getConfigPath(); return Filesystem::readablePath($path); }
}