commands to show readme and extract config template
[bdrem.git] / src / bdrem / Config.php
index 5d34f7607fe25409c2b4059a7a9ac3319cf5d89c..65e353d3518dd7f9f5a1eab44983117f457aee4c 100644 (file)
@@ -4,28 +4,30 @@ namespace bdrem;
 class Config
 {
     public $source;
-    public $daysBefore;
-    public $daysAfter;
+    public $date;
+    public $daysPrev = 3;
+    public $daysNext = 7;
     public $locale;
+    public $stopOnEmpty = false;
+    public $cfgFileExists;
 
     public function load()
     {
         $f = __DIR__ . '/../../data/bdrem.config.php';
         if (file_exists($f)) {
+            $this->cfgFileExists = true;
             return $this->loadFile($f);
         }
 
-        throw new \Exception('No config file found');
+        $this->cfgFileExists = false;
     }
 
     protected function loadFile($filename)
     {
         include $filename;
-        $this->source = $source;
-        $this->daysBefore = $daysBefore;
-        $this->daysAfter = $daysAfter;
-        if (isset($locale)) {
-            $this->locale = $locale;
+        $vars = get_defined_vars();
+        foreach ($vars as $k => $value) {
+            $this->$k = $value;
         }
     }
 
@@ -40,5 +42,23 @@ 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 == '') {
+            return $default;
+        }
+        return $this->$varname;
+    }
 }
 ?>