@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
at upstream/main 75 lines 1.9 kB view raw
1<?php 2 3final 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 Exception( 33 pht( 34 'Configuration file "%s" exists, but could not be read.', 35 $path), 36 0, 37 $ex); 38 } 39 40 try { 41 $result = phutil_json_decode($data); 42 } catch (PhutilJSONParserException $ex) { 43 throw new Exception( 44 pht( 45 'Configuration file "%s" exists and is readable, but the content '. 46 'is not valid JSON. You may have edited this file manually and '. 47 'introduced a syntax error by mistake. Correct the file syntax '. 48 'to continue.', 49 $path), 50 0, 51 $ex); 52 } 53 54 return $result; 55 } 56 57 private function saveConfig() { 58 $config = $this->getSource()->getAllKeys(); 59 $json = new PhutilJSON(); 60 $data = $json->encodeFormatted($config); 61 Filesystem::writeFile($this->getConfigPath(), $data); 62 } 63 64 private function getConfigPath() { 65 $root = dirname(phutil_get_library_root('phabricator')); 66 $path = $root.'/conf/local/local.json'; 67 return $path; 68 } 69 70 public function getReadablePath() { 71 $path = $this->getConfigPath(); 72 return Filesystem::readablePath($path); 73 } 74 75}