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
54 * Locale to render the dates in, e.g. "de_DE.UTF-8"
60 * Renderer name to use (e.g. "console")
66 * Event source configuration.
67 * - First value is source name ("Ldap", "Sql")
68 * - Second value is the source configuration
74 * Do not output anything if there are no events to show
80 * List of config file paths that were tried to load
83 public $cfgFiles = array();
86 * If a configuration file could be found
89 public $cfgFileExists;
94 * Init configuration file path loading
96 public function __construct()
98 $this->loadConfigFilePaths();
102 * Load the configuration from the first configuration file found.
106 public function load()
108 foreach ($this->cfgFiles as $file) {
109 if (file_exists($file)) {
110 $this->cfgFileExists = true;
111 return $this->loadFile($file);
114 $this->cfgFileExists = false;
118 * Load possible configuration file paths into $this->cfgFiles.
122 protected function loadConfigFilePaths()
124 $pharFile = \Phar::running();
125 if ($pharFile == '') {
126 $this->cfgFiles[] = __DIR__ . '/../../data/bdrem.config.php';
128 //remove phar:// from the path
129 $this->cfgFiles[] = substr($pharFile, 7) . '.config.php';
132 //TODO: add ~/.config/bdrem.php
134 $this->cfgFiles[] = '/etc/bdrem.php';
138 * Load a single configuration file and set the config class variables
140 * @param string $filename Configuration file path
144 protected function loadFile($filename)
147 $vars = get_defined_vars();
148 foreach ($vars as $k => $value) {
149 if (!isset($this->$k) || $this->$k === null) {
156 * Load a event source from $this->source.
157 * Class name has to be \bdrem\Source_$source
159 * @return object Source object
161 public function loadSource()
163 if ($this->source === null) {
164 throw new \Exception('No source defined');
167 $settings = $this->source;
168 $class = '\\bdrem\\Source_' . array_shift($settings);
170 return new $class($settings[0]);
174 * Set the current date
176 * @param string $date Date in any format
180 public function setDate($date)
182 if ($date === null) {
183 $this->date = date('Y-m-d');
185 $dt = new \DateTime($date);
186 $this->date = $dt->format('Y-m-d');
191 * Get a configuration variable
193 * @param string $varname Configuration variable name
194 * @param string $default Default value in case the variable is not set
197 * @return mixed Configuration value or default
199 public function get($varname, $default = '')
201 if (!isset($this->$varname) || $this->$varname == '') {
204 return $this->$varname;