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;
+ }
}
}