1<?php 2 3abstract class ArcanistFilesystemConfigurationSource 4 extends ArcanistDictionaryConfigurationSource { 5 6 private $path; 7 8 public function __construct($path) { 9 $this->path = $path; 10 11 $values = array(); 12 if (Filesystem::pathExists($path)) { 13 $contents = Filesystem::readFile($path); 14 if (strlen(trim($contents))) { 15 $values = phutil_json_decode($contents); 16 } 17 } 18 19 $values = $this->didReadFilesystemValues($values); 20 21 parent::__construct($values); 22 } 23 24 public function getPath() { 25 return $this->path; 26 } 27 28 public function getSourceDisplayName() { 29 return pht('%s (%s)', $this->getFileKindDisplayName(), $this->getPath()); 30 } 31 32 abstract public function getFileKindDisplayName(); 33 34 protected function didReadFilesystemValues(array $values) { 35 return $values; 36 } 37 38 protected function writeToStorage($values) { 39 $content = id(new PhutilJSON()) 40 ->encodeFormatted($values); 41 42 Filesystem::writeFile($this->path, $content); 43 } 44 45} 46