9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/bdrem.htm
17 * Configuration options for bdrem
21 * @author Christian Weiske <cweiske@cweiske.de>
22 * @copyright 2014 Christian Weiske
23 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24 * @version Release: @package_version@
25 * @link http://cweiske.de/bdrem.htm
30 * Current date, YYYY-MM-DD
36 * Days to show before $date
42 * Days to show after $date
48 * Locale to render the dates in, e.g. "de_DE.UTF-8"
54 * Renderer name to use (e.g. "console")
60 * Event source configuration.
61 * - First value is source name ("Ldap", "Sql")
62 * - Second value is the source configuration
68 * Do not output anything if there are no events to show
74 * List of config file paths that were tried to load
77 public $cfgFiles = array();
80 * If a configuration file could be found
83 public $cfgFileExists;
88 * Init configuration file path loading
90 public function __construct()
92 $this->loadConfigFilePaths();
96 * Load the configuration from the first configuration file found.
100 public function load()
102 foreach ($this->cfgFiles as $file) {
103 if (file_exists($file)) {
104 $this->cfgFileExists = true;
105 return $this->loadFile($file);
108 $this->cfgFileExists = false;
112 * Load possible configuration file paths into $this->cfgFiles.
116 protected function loadConfigFilePaths()
118 $pharFile = \Phar::running();
119 if ($pharFile == '') {
120 $this->cfgFiles[] = __DIR__ . '/../../data/bdrem.config.php';
122 //remove phar:// from the path
123 $this->cfgFiles[] = substr($pharFile, 7) . '.config.php';
126 //TODO: add ~/.config/bdrem.php
128 $this->cfgFiles[] = '/etc/bdrem.php';
132 * Load a single configuration file and set the config class variables
134 * @param string $filename Configuration file path
138 protected function loadFile($filename)
141 $vars = get_defined_vars();
142 foreach ($vars as $k => $value) {
143 if (!isset($this->$k) || $this->$k === null) {
150 * Load a event source from $this->source.
151 * Class name has to be \bdrem\Source_$source
153 * @return object Source object
155 public function loadSource()
157 if ($this->source === null) {
158 throw new \Exception('No source defined');
161 $settings = $this->source;
162 $class = '\\bdrem\\Source_' . array_shift($settings);
164 return new $class($settings[0]);
168 * Set the current date
170 * @param string $date Date in any format
174 public function setDate($date)
176 if ($date === null) {
177 $this->date = date('Y-m-d');
179 $dt = new \DateTime($date);
180 $this->date = $dt->format('Y-m-d');
185 * Get a configuration variable
187 * @param string $varname Configuration variable name
188 * @param string $default Default value in case the variable is not set
191 * @return mixed Configuration value or default
193 public function get($varname, $default = '')
195 if (!isset($this->$varname) || $this->$varname == '') {
198 return $this->$varname;