load config file from different locations, including phar
[bdrem.git] / src / bdrem / Config.php
index 65e353d3518dd7f9f5a1eab44983117f457aee4c..a79b1b3c5b53ec21799689f9903d057a1189d448 100644 (file)
@@ -9,19 +9,37 @@ class Config
     public $daysNext = 7;
     public $locale;
     public $stopOnEmpty = false;
     public $daysNext = 7;
     public $locale;
     public $stopOnEmpty = false;
+
+    public $cfgFiles = array();
     public $cfgFileExists;
 
     public function load()
     {
     public $cfgFileExists;
 
     public function load()
     {
-        $f = __DIR__ . '/../../data/bdrem.config.php';
-        if (file_exists($f)) {
-            $this->cfgFileExists = true;
-            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;
     }
 
         $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;
     protected function loadFile($filename)
     {
         include $filename;