show error, not exception
[bdrem.git] / src / bdrem / Config.php
index 37c4c641a3d512aea937dba10e8ecd44ae62fc8f..a79b1b3c5b53ec21799689f9903d057a1189d448 100644 (file)
@@ -5,19 +5,39 @@ class Config
 {
     public $source;
     public $date;
-    public $daysPrev;
-    public $daysNext;
+    public $daysPrev = 3;
+    public $daysNext = 7;
     public $locale;
-    public $stopOnEmpty;
+    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';
+        }
+
+        //TODO: add ~/.config/bdrem.php
 
-        throw new \Exception('No config file found');
+        $this->cfgFiles[] = '/etc/bdrem.php';
     }
 
     protected function loadFile($filename)