14 public $cfgFiles = array();
15 public $cfgFileExists;
19 public function __construct()
21 $this->loadConfigFilePaths();
24 public function load()
26 foreach ($this->cfgFiles as $file) {
27 if (file_exists($file)) {
28 $this->cfgFileExists = true;
29 return $this->loadFile($file);
32 $this->cfgFileExists = false;
35 protected function loadConfigFilePaths()
37 $pharFile = \Phar::running();
38 if ($pharFile == '') {
39 $this->cfgFiles[] = __DIR__ . '/../../data/bdrem.config.php';
41 //remove phar:// from the path
42 $this->cfgFiles[] = substr($pharFile, 7) . '.config.php';
45 //TODO: add ~/.config/bdrem.php
47 $this->cfgFiles[] = '/etc/bdrem.php';
50 protected function loadFile($filename)
53 $vars = get_defined_vars();
54 foreach ($vars as $k => $value) {
55 if (!isset($this->$k) || $this->$k === null) {
61 public function loadSource()
63 if ($this->source === null) {
64 throw new \Exception('No source defined');
67 $settings = $this->source;
68 $class = '\\bdrem\\Source_' . array_shift($settings);
70 return new $class($settings[0]);
73 public function setDate($date)
76 $this->date = date('Y-m-d');
78 $dt = new \DateTime($date);
79 $this->date = $dt->format('Y-m-d');
83 public function get($varname, $default = '')
85 if (!isset($this->$varname) || $this->$varname == '') {
88 return $this->$varname;