include lib/ dir, use it as include path
[bdrem.git] / src / bdrem / Config.php
index 65e353d3518dd7f9f5a1eab44983117f457aee4c..57d0cfd7d1995527cb8163b3bb0355756071e417 100644 (file)
@@ -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;
+            }
         }
     }