X-Git-Url: https://git.cweiske.de/bdrem.git/blobdiff_plain/2e18a05a2cedf343b0d0f5fd3e4e6a8d65e2647e..95681cad57a3bb6198162d0e94dc8f700ced60af:/src/bdrem/Config.php diff --git a/src/bdrem/Config.php b/src/bdrem/Config.php index 65e353d..57d0cfd 100644 --- a/src/bdrem/Config.php +++ b/src/bdrem/Config.php @@ -3,31 +3,58 @@ namespace bdrem; class Config { - public $source; public $date; - public $daysPrev = 3; - public $daysNext = 7; + public $daysPrev; + public $daysNext; public $locale; - public $stopOnEmpty = false; + public $renderer; + public $source; + public $stopOnEmpty; + + public $cfgFiles = array(); public $cfgFileExists; + + + public function __construct() + { + $this->loadConfigFilePaths(); + } + public function load() { - $f = __DIR__ . '/../../data/bdrem.config.php'; - if (file_exists($f)) { - $this->cfgFileExists = true; - return $this->loadFile($f); + foreach ($this->cfgFiles as $file) { + if (file_exists($file)) { + $this->cfgFileExists = true; + return $this->loadFile($file); + } } - $this->cfgFileExists = false; } + protected function loadConfigFilePaths() + { + $pharFile = \Phar::running(); + if ($pharFile == '') { + $this->cfgFiles[] = __DIR__ . '/../../data/bdrem.config.php'; + } else { + //remove phar:// from the path + $this->cfgFiles[] = substr($pharFile, 7) . '.config.php'; + } + + //TODO: add ~/.config/bdrem.php + + $this->cfgFiles[] = '/etc/bdrem.php'; + } + protected function loadFile($filename) { include $filename; $vars = get_defined_vars(); foreach ($vars as $k => $value) { - $this->$k = $value; + if (!isset($this->$k) || $this->$k === null) { + $this->$k = $value; + } } }