add stopOnEmpty and date parameters
[bdrem.git] / src / bdrem / Config.php
1 <?php
2 namespace bdrem;
3
4 class Config
5 {
6     public $source;
7     public $date;
8     public $daysPrev;
9     public $daysNext;
10     public $locale;
11     public $stopOnEmpty;
12
13     public function load()
14     {
15         $f = __DIR__ . '/../../data/bdrem.config.php';
16         if (file_exists($f)) {
17             return $this->loadFile($f);
18         }
19
20         throw new \Exception('No config file found');
21     }
22
23     protected function loadFile($filename)
24     {
25         include $filename;
26         $vars = get_defined_vars();
27         foreach ($vars as $k => $value) {
28             $this->$k = $value;
29         }
30     }
31
32     public function loadSource()
33     {
34         if ($this->source === null) {
35             throw new \Exception('No source defined');
36         }
37
38         $settings = $this->source;
39         $class = '\\bdrem\\Source_' . array_shift($settings);
40
41         return new $class($settings[0]);
42     }
43
44     public function setDate($date)
45     {
46         if ($date === null) {
47             $this->date = date('Y-m-d');
48         } else {
49             $dt = new \DateTime($date);
50             $this->date = $dt->format('Y-m-d');
51         }
52     }
53
54     public function get($varname, $default = '')
55     {
56         if (!isset($this->$varname) || $this->$varname == '') {
57             return $default;
58         }
59         return $this->$varname;
60     }
61 }
62 ?>