namespace = $namespace; $this->config_filename = $config_filename; try { $this->data = self::load($this->config_filename); } catch (Minz_FileNotExistException $e) { if (is_null($default_filename)) { throw $e; } } $this->default_filename = $default_filename; if (!is_null($this->default_filename)) { $this->data_default = self::load($this->default_filename); } $this->_configurationSetter($configuration_setter); } /** * Set a configuration setter for the current configuration. * @param $configuration_setter the setter to call when modifying data. It * must implement an handle($key, $value) method. */ public function _configurationSetter($configuration_setter) { if (is_callable(array($configuration_setter, 'handle'))) { $this->configuration_setter = $configuration_setter; } } /** * Return the value of the given param. * * @param $key the name of the param. * @param $default default value to return if key does not exist. * @return the value corresponding to the key. * @throws Minz_ConfigurationParamException if the param does not exist */ public function param($key, $default = null) { if (isset($this->data[$key])) { return $this->data[$key]; } elseif (!is_null($default)) { return $default; } elseif (isset($this->data_default[$key])) { return $this->data_default[$key]; } else { Minz_Log::warning($key . ' does not exist in configuration'); return null; } } /** * A wrapper for param(). */ public function __get($key) { return $this->param($key); } /** * Set or remove a param. * * @param $key the param name to set. * @param $value the value to set. If null, the key is removed from the configuration. */ public function _param($key, $value = null) { if (!is_null($this->configuration_setter)) { $value = $this->configuration_setter->handle($key, $value); } if (isset($this->data[$key]) && is_null($value)) { unset($this->data[$key]); } elseif (!is_null($value)) { $this->data[$key] = $value; } } /** * A wrapper for _param(). */ public function __set($key, $value) { $this->_param($key, $value); } /** * Save the current configuration in the configuration file. */ public function save() { $back_filename = $this->config_filename . '.bak.php'; @rename($this->config_filename, $back_filename); if (file_put_contents($this->config_filename, "data, true) . ';', LOCK_EX) === false) { return false; } // Clear PHP 5.5+ cache for include if (function_exists('opcache_invalidate')) { opcache_invalidate($this->config_filename); } return true; } }