Source for file config_loader.class.php
Documentation is available at config_loader.class.php
// *** Tangra (Application Framework and Tools for PHP)
* Contains class Config_Loader
require_once(TANGRA_MAIN_DIR. 'exceptions/te_config_loader_error_key_missing.class.php');
require_once(TANGRA_MAIN_DIR. 'exceptions/te_config_loader_error.class.php');
* Base class for configuration loaders.
* Base class for all classes of Config_Loader family. Used to define the interface.
* Config_Loader classes are intended to provide unified mechanism for loading configuration from diferent sources as files, db, net connection, etc.
* $pairs holds key - value pairs in associative array. Key is the name of configuration value and value - the value itself.
* It is supposed loading of the configuration from external resource as file or DB to be performed at construction time of Config_Loader objects.
* That means that when you createn new instance of Config_Loader class (some descendant of Config_Loader that is not "abstract") your configuration will be loaded and you can use get_conf_value method to extract values.
* @param mutable $config_resource Intended to be mutable type, i.e. different Config_Loader descendants may require different paramter type.
* Gets coresponding to $key configuration value.
* @param string key name of configuration setting
* @param boolean $halt_on_missing if true exception will be trown if configuration setting specified by $key
* @throws TE_Config_Loader_Error_Key_Missing
$ret = $this->pairs[$key];
// $ret = trim($this->pairs[$key]);
// $ret = $this->expand($ret, $key);
throw new TE_Config_Loader_Error_Key_Missing('Key: '. $key. ' is not found.');
* Auxiliary method that may be used to set the internal private $pairs variable.
* This method normally is not called directly - it is intended to be used by writers of new Config_Loader descendants that require weird approach.
* @param array $pairs Array must be simple associative array with $key => $value structure.
* @throws Tangra_Exception
Tangra_Exception('Parameter $pairs is not an array. Current value: '. $pairs);
* Returns all key-value pairs
* Expands keys that are present in values
* If key starts with _AUTO a global function will be called to return the value. Name of the global function have to be strtolower($key) where $key is the key to be expanded.
* If we have in machine_specific.conf the following:
* ROOT=%_AUTO_DETECT_ROOT%
* function with name _auto_detect_root will be called and returned value will be used to replace %_AUTO_DETECT_ROOT%
* @param string $current_key
protected function expand($value, $current_key) {
if ($current_key != $key) {
throw new TE_Config_Loader_Error('Fatal error occured while trying to expand value "'. $value. '" for key "'. $current_key. '". Recursion.');
* Extracts all keys (delimited by % from both sides)
* Extracts single key that start at position $start in string $value
$end = strpos($value, '%', $start + 1);
$ret = substr($value, $start + 1, $end - $start - 1);
throw new TE_Config_Loader_Error('Fatal error occured while trying to expand value "'. $value. '". No end delimiter % found.');
* Adds new key-value pair
public function add_pair($key, $value) {
$this->pairs[$key] = $value;
throw new TE_Config_Loader_Error("Key $key already exists.");
|