X-Git-Url: https://git.cweiske.de/bdrem.git/blobdiff_plain/6506b1ebe1ecaa6630d6d849c39b9e9d53603699..deb49c81c9d269708c6252647c1afb668b982d97:/src/bdrem/Config.php diff --git a/src/bdrem/Config.php b/src/bdrem/Config.php index 7a0fd68..a79b1b3 100644 --- a/src/bdrem/Config.php +++ b/src/bdrem/Config.php @@ -5,18 +5,39 @@ class Config { public $source; public $date; - public $daysBefore; - public $daysAfter; + public $daysPrev = 3; + public $daysNext = 7; public $locale; + public $stopOnEmpty = false; + + public $cfgFiles = array(); + public $cfgFileExists; public function load() { - $f = __DIR__ . '/../../data/bdrem.config.php'; - if (file_exists($f)) { - return $this->loadFile($f); + $this->loadConfigFilePaths(); + 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'; } - throw new \Exception('No config file found'); + //TODO: add ~/.config/bdrem.php + + $this->cfgFiles[] = '/etc/bdrem.php'; } protected function loadFile($filename) @@ -40,6 +61,16 @@ class Config return new $class($settings[0]); } + public function setDate($date) + { + if ($date === null) { + $this->date = date('Y-m-d'); + } else { + $dt = new \DateTime($date); + $this->date = $dt->format('Y-m-d'); + } + } + public function get($varname, $default = '') { if (!isset($this->$varname) || $this->$varname == '') {