/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * Sections are defined in the XML as children of the root element. * * In order to extend another section, a section defines the "extends" * attribute having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "extends". * * @param string $filename * @param mixed $section * @param boolean $allowModifications * @throws Zend_Config_Exception * @return void */ public function __construct($filename, $section = null, $allowModifications = false) { if (empty($filename)) { throw new Zend_Config_Exception('Filename is not set'); } $config = simplexml_load_file($filename); if (null === $section) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config->{$sectionName})) { throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}"); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config->{$section})) { throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}"); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // section in the XML file contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } $this->_loadedSection = $section; }
public function __construct($config = null, $type = 'array', $allowModifications = true) { parent::__construct(array(), $allowModifications); if (!is_null($config)) { $this->append($config, $type); } }
public function __construct($string, $section = null, $options = false) { if (empty($string)) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('String is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['nestSeparator'])) { $this->_nestSeparator = (string) $options['nestSeparator']; } if (isset($options['skipExtends'])) { $this->_skipExtends = (bool) $options['skipExtends']; } } $iniArray = $this->_loadIniFile($string); if (null === $section) { // Load entire file $dataArray = array(); foreach ($iniArray as $sectionName => $sectionData) { if (!is_array($sectionData)) { $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData)); } else { $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName); } } parent::__construct($dataArray, $allowModifications); } else { // Load one or more sections if (!is_array($section)) { $section = array($section); } $dataArray = array(); foreach ($section as $sectionName) { if (!isset($iniArray[$sectionName])) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$string}"); } $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } $this->_loadedSection = $section; }
/** * Open and validate a config file. * * uses CONFIG_PARTYCAL_MODE_EXCEPTIONS and CONFIG_PARTYCAL_MODE_STDERR to * throw exceptions or output errors * * @throws Config_Exception_PartyCal * * @param $node String needed node * @param $mode Long mode for error handling, Exceptions are default * * @todo implement Exception/sdterr handling */ public function __construct($node, $mode = NULL) { parent::__construct(new Zend_Config_Ini($_ENV['PARTYCAL_CONFIG'], $node)); $config_validator = new Config_Validator_PartyCal($_ENV['PARTYCAL_CONFIG'], CONFIG_VALIDATOR_PARTYCAL_MODE_SCAN); try { $config_validator->validate(); } catch (Exception $e) { //check mode //write to stderr } }
public final function __construct() { $backtrace = debug_backtrace(); $class = $backtrace[1]['class']; if ($class !== get_class($this)) { throw new RuntimeException('Não permitida chamada externa'); } $method = strtolower($backtrace[1]['function']); if ($method !== 'getinstance') { throw new RuntimeException('Não permitida chamada externa'); } parent::__construct(array(), TRUE); }
/** * Class constructor * @var array|Zend_Config */ public function __construct($config) { if (is_array($config)) { $config = new Zend_Config($config); } if (!$config instanceof Zend_Config) { throw new Zend_Config_Exception('Config must be an array or Zend_Config'); } parent::__construct(array(), true); $this->merge($config); $this->_processPlaceholders($this); $this->setReadOnly(); }
/** * Prüft das Vorhandensein der Einstellungsdatei und lädt diese * @param string $filename * @throws InvalidArgumentException */ public function __construct($filename) { if (Zend_Registry::isRegistered('Dragon_Repository_Registry')) { foreach (array_reverse(Zend_Registry::get('Dragon_Repository_Registry')->getRepositories()) as $repositoryname => $directorypath) { $filepath = $directorypath . '/config/' . $filename . '.php'; if (is_file($filepath)) { parent::__construct(require $filepath); return; } } } $filepath = DRAGONJSONSERVER_PATH . '/config/' . $filename . '.php'; if (!is_file($filepath)) { throw new Dragon_Application_Exception_System('incorrect configfile', array('filename' => $filename)); } parent::__construct(require $filepath); }
public function __construct($name, $config = null) { $this->name = $name; $this->config = $config; try { $this->basedir = Zend_Registry::get('config_basedir'); } catch (Zend_Exception $e) { $this->basedir = 'private/config/'; } $this->filename = $this->basedir . $name . '.php'; if ($config === null) { if (file_exists($this->filename)) { /* Ne pas utiliser include, car le cache d'include fausse certains cas, notamment à l'installation. */ $php = str_replace('<?php', '', file_get_contents($this->filename)); $config = eval($php); } if (!is_array($config)) { $config = array(); } } parent::__construct($config, true); }
/** * Loads the section $section from the config file encoded as JSON * * Sections are defined as properties of the main object * * In order to extend another section, a section defines the "_extends" * property having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "_extends". * * @param string $json JSON file or string to process * @param mixed $section Section to process * @param boolean $options Whether modifiacations are allowed at runtime * @throws Zend_Config_Exception When JSON text is not set or cannot be loaded * @throws Zend_Config_Exception When section $sectionName cannot be found in $json */ public function __construct($json, $section = null, $options = false) { if (empty($json)) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { foreach ($options as $key => $value) { switch (strtolower($key)) { case 'allow_modifications': case 'allowmodifications': $allowModifications = (bool) $value; break; case 'skip_extends': case 'skipextends': $this->_skipExtends = (bool) $value; break; case 'ignore_constants': case 'ignoreconstants': $this->_ignoreConstants = (bool) $value; break; default: break; } } } set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed if ($json[0] != '{') { $json = file_get_contents($json); } restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } // Replace constants if (!$this->_ignoreConstants) { $json = $this->_replaceConstants($json); } // Parse/decode try { $config = Zend_Json::decode($json); } catch (Zend_Json_Exception $e) { // decode failed require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Error parsing JSON data"); } if ($section === null) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config[$sectionName])) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName)); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config[$section])) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // Section in the JSON data contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } $this->_loadedSection = $section; }
public function __construct($node) { parent::__construct(new Zend_Config_Ini($_ENV['PARTYCAL_CONFIG'], $node)); }
/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * If any keys with $section are called "extends", then the section * pointed to by the "extends" is then included into the properties. * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "extends". * * If any key includes a ".", then this will act as a separator to * create a sub-property. * * example ini file: * [all] * db.connection = database * hostname = live * * [staging] * extends = all * hostname = staging * * after calling $data = new Zend_Config_Ini($file, 'staging'); then * $data->hostname === "staging" * $data->db->connection === "database" * * @param string $filename * @param mixed $section * @param boolean $allowModifications * @throws Zend_Config_Exception */ public function __construct($filename, $section, $allowModifications = false) { if (empty($filename)) { throw new Zend_Config_Exception('Filename is not set'); } $iniArray = parse_ini_file($filename, true); $preProcessedArray = array(); foreach ($iniArray as $key => $data) { $bits = explode(':', $key); $numberOfBits = count($bits); $thisSection = trim($bits[0]); switch (count($bits)) { case 1: $preProcessedArray[$thisSection] = $data; break; case 2: $extendedSection = trim($bits[1]); $preProcessedArray[$thisSection] = array_merge(array(';extends' => $extendedSection), $data); break; default: throw new Zend_Config_Exception("Section '{$thisSection}' may not extend multiple sections in {$filename}"); } } if (null === $section) { $dataArray = array(); foreach ($preProcessedArray as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($preProcessedArray, $sectionName); } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($preProcessedArray[$sectionName])) { throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}"); } $dataArray = array_merge($this->_processExtends($preProcessedArray, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($preProcessedArray[$section])) { throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}"); } parent::__construct($this->_processExtends($preProcessedArray, $section), $allowModifications); } $this->_loadedSection = $section; }
/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * If the section name contains a ":" then the section name to the right * is loaded and included into the properties. Note that the keys in * this $section will override any keys of the same * name in the sections that have been included via ":". * * If the $section is null, then all sections in the ini file are loaded. * * If any key includes a ".", then this will act as a separator to * create a sub-property. * * example ini file: * [all] * db.connection = database * hostname = live * * [staging : all] * hostname = staging * * after calling $data = new Zend_Config_Ini($file, 'staging'); then * $data->hostname === "staging" * $data->db->connection === "database" * * The $config parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $config = array( * 'allowModifications' => false, * 'nestSeparator' => '->' * ); * * @param string $filename * @param string|null $section * @param boolean|array $config * @throws Zend_Config_Exception */ public function __construct($filename, $section = null, $config = false) { if (empty($filename)) { /** @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($config)) { $allowModifications = $config; } elseif (is_array($config)) { if (isset($config['allowModifications'])) { $allowModifications = (bool) $config['allowModifications']; } if (isset($config['nestSeparator'])) { $this->_nestSeparator = (string) $config['nestSeparator']; } } $iniArray = parse_ini_file($filename, true); $preProcessedArray = array(); foreach ($iniArray as $key => $data) { $bits = explode(':', $key); $numberOfBits = count($bits); $thisSection = trim($bits[0]); switch (count($bits)) { case 1: $preProcessedArray[$thisSection] = $data; break; case 2: $extendedSection = trim($bits[1]); $preProcessedArray[$thisSection] = array_merge(array(';extends'=>$extendedSection), $data); break; default: /** @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '$thisSection' may not extend multiple sections in $filename"); } } if (null === $section) { $dataArray = array(); foreach ($preProcessedArray as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($preProcessedArray, $sectionName); } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($preProcessedArray[$sectionName])) { /** @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename"); } $dataArray = array_merge($this->_processExtends($preProcessedArray, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($preProcessedArray[$section])) { /** @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '$section' cannot be found in $filename"); } parent::__construct($this->_processExtends($preProcessedArray, $section), $allowModifications); } $this->_loadedSection = $section; }
/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * If the section name contains a ":" then the section name to the right * is loaded and included into the properties. Note that the keys in * this $section will override any keys of the same name in the sections * that have been included via ":". * * If the $section is null, then all sections in the ini file are loaded. * * If any key includes a ".", then this will act as a separator to create * a sub-property. * * example ini file: * [all] * db.connection = database * hostname = live * * [staging : all] * hostname = staging * * after calling $data = new Zend_Config_Ini($file, 'staging'); then * $data->hostname === "staging" * $data->db->connection === "database" * * The $options parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $options = array( * 'allowModifications' => false, * 'nestSeparator' => '->' * ); * * @param string $filename * @param string|null $section * @param boolean|array $options * @throws Zend_Config_Exception */ public function __construct($filename, $section = null, $options = false) { if (empty($filename)) { /** @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } // process $options $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['nestSeparator'])) { $this->_nestSeparator = (string) $options['nestSeparator']; } } $iniArray = $this->_loadIniFile($filename); if (null === $section) { // Load entire file $config = $this->_loadAllSections($iniArray); } elseif (is_array($section)) { // Load multiple sections $config = array(); foreach ($section as $sectionName) { $config = array_merge($this->_loadSection($iniArray, $sectionName), $config); } } else { // Load single section $config = $this->_loadSection($iniArray, $section); } parent::__construct($config, $allowModifications); // Set _loadedSection after calling parent's constructor as it // will initialize it to null $this->_loadedSection = $section; }
/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * Sections are defined in the XML as children of the root element. * * In order to extend another section, a section defines the "extends" * attribute having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "extends". * * @param string $filename * @param mixed $section * @param boolean $allowModifications * @throws Zend_Config_Exception * @return void */ public function __construct($filename, $section = null, $allowModifications = false) { if (empty($filename)) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $old_error_handler = set_error_handler(array(__CLASS__, 'simplexmlLoadFileFileErrorHandler')); $config = simplexml_load_file($filename); restore_error_handler(); if (null === $section) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config->$sectionName)) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename"); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config->$section)) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '$section' cannot be found in $filename"); } $dataArray = $this->_processExtends($config, $section); if(!is_array($dataArray)) { // section in the XML file contains just one top level string $dataArray = array($section=>$dataArray); } parent::__construct($dataArray, $allowModifications); } $this->_loadedSection = $section; }
/** * Loads the section $section from the config file encoded as JSON * * Sections are defined as properties of the main object * * In order to extend another section, a section defines the "_extends" * property having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "_extends". * * @param string $json JSON file or string to process * @param mixed $section Section to process * @param boolean $options Whether modifiacations are allowed at runtime * @throws Zend_Config_Exception When JSON text is not set or cannot be loaded * @throws Zend_Config_Exception When section $sectionName cannot be found in $json */ public function __construct($json, $section = null, $options = false) { if (empty($json)) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['skipExtends'])) { $this->_skipExtends = (bool) $options['skipExtends']; } } set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed if ($json[0] != '{') { $json = file_get_contents($json); } restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } $config = Zend_Json::decode($json); if ($config == null) { // decode failed require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Error parsing JSON data"); } if ($section === null) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } else { if (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config->{$sectionName})) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in the data"); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config[$section])) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$section}' cannot be found in the data"); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // Section in the JSON data contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } } $this->_loadedSection = $section; }
/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * If the section name contains a ":" then the section name to the right * is loaded and included into the properties. Note that the keys in * this $section will override any keys of the same * name in the sections that have been included via ":". * * If the $section is null, then all sections in the ini file are loaded. * * If any key includes a ".", then this will act as a separator to * create a sub-property. * * example ini file: * [all] * db.connection = database * hostname = live * * [staging : all] * hostname = staging * * after calling $data = new Zend_Config_Ini($file, 'staging'); then * $data->hostname === "staging" * $data->db->connection === "database" * * The $options parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $options = array( * 'allowModifications' => false, * 'nestSeparator' => '->' * ); * * @param string $filename * @param string|null $section * @param boolean|array $options * @throws Zend_Config_Exception * @return void */ public function __construct($filename, $section = null, $options = false) { if (empty($filename)) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['nestSeparator'])) { $this->_nestSeparator = (string) $options['nestSeparator']; } } set_error_handler(array($this, '_loadFileErrorHandler')); $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } $preProcessedArray = array(); foreach ($iniArray as $key => $data) { $bits = explode(':', $key); $thisSection = trim($bits[0]); switch (count($bits)) { case 1: $preProcessedArray[$thisSection] = $data; break; case 2: $extendedSection = trim($bits[1]); $preProcessedArray[$thisSection] = array_merge(array(';extends' => $extendedSection), $data); break; default: /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$thisSection}' may not extend multiple sections in {$filename}"); } } if (null === $section) { $dataArray = array(); foreach ($preProcessedArray as $sectionName => $sectionData) { if (!is_array($sectionData)) { $dataArray = array_merge_recursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData)); } else { $dataArray[$sectionName] = $this->_processExtends($preProcessedArray, $sectionName); } } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($preProcessedArray[$sectionName])) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}"); } $dataArray = array_merge($this->_processExtends($preProcessedArray, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($preProcessedArray[$section])) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}"); } parent::__construct($this->_processExtends($preProcessedArray, $section), $allowModifications); } $this->_loadedSection = $section; }
/** * コンストラクタ */ public function __construct($path, $allowModifications = false) { parent::__construct(require $path, $allowModifications); }
/** * Loads the section $section from the config file encoded as YAML * * Sections are defined as properties of the main object * * In order to extend another section, a section defines the "_extends" * property having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "_extends". * * Options may include: * - allow_modifications: whether or not the config object is mutable * - skip_extends: whether or not to skip processing of parent configuration * - yaml_decoder: a callback to use to decode the Yaml source * * @param string $yaml YAML file to process * @param mixed $section Section to process * @param array|boolean $options */ public function __construct($yaml, $section = null, $options = false) { if (empty($yaml)) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $ignoreConstants = $staticIgnoreConstants = self::ignoreConstants(); $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { foreach ($options as $key => $value) { switch (strtolower($key)) { case 'allow_modifications': case 'allowmodifications': $allowModifications = (bool) $value; break; case 'skip_extends': case 'skipextends': $this->_skipExtends = (bool) $value; break; case 'ignore_constants': case 'ignoreconstants': $ignoreConstants = (bool) $value; break; case 'yaml_decoder': case 'yamldecoder': $this->setYamlDecoder($value); break; default: break; } } } // Suppress warnings and errors while loading file set_error_handler(array($this, '_loadFileErrorHandler')); $yaml = file_get_contents($yaml); restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } // Override static value for ignore_constants if provided in $options self::setIgnoreConstants($ignoreConstants); // Parse YAML $config = call_user_func($this->getYamlDecoder(), $yaml); // Reset original static state of ignore_constants self::setIgnoreConstants($staticIgnoreConstants); if (null === $config) { // decode failed require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Error parsing YAML data"); } if (null === $section) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config[$sectionName])) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config[$section])) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // Section in the yaml data contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } $this->_loadedSection = $section; }
/** * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * If the section name contains a ":" then the section name to the right * is loaded and included into the properties. Note that the keys in * this $section will override any keys of the same * name in the sections that have been included via ":". * * If the $section is null, then all sections in the ini file are loaded. * * If any key includes a ".", then this will act as a separator to * create a sub-property. * * example ini file: * [all] * db.connection = database * hostname = "live" * * [staging:all] * hostname = "staging" * * You can use the '|' to specify a section from an extended ini file * * another ini file ( extend.ini ): * [fooExtend] * hostname = "extendedValue" * * [foo:c:/path/to/file/extend.ini|fooExtend] * hostname = "staging" * * !!! The value must be quoted !!!! * * You can concat evaluated elements as a value with the {E:} block. * Example: * * [foo:extend{E:fooClass::getUsername()}] * will be the same: * [foo:extendTestUser] * * * or * [foo:c:/{E:fooClass::getFilePath()}/extend.ini|fooExtend] * will be the same: * [foo:c:/path/to/file/extend.ini|fooExtend] * * * or * [foo] * file.path = "c:/{E:fooClass::getFilePath()}" * will be the same: * [foo] * file.path = "c:/path/to/file" * * * or * [Db] * host.name = "FooName" * * [foo:extend{Db.host.name}] * will be the same: * [foo:extendFooName] * * * or * * [Logger] * file.path = "c:/path/to/file" * * [foo:{Logger.file.path}/log.ini|Log] * will be the same: * [foo:c:/path/to/file/log.ini|Log] * * * or * * [Logger] * file.path = "c:/path/to/file" * * [Log] * file = "{Logger.file.path}/debug.log" * will be the same: * [Log] * file = "c:/path/to/file/debug.log" * * * after calling $data = new Zend_Config_Ini($file, 'staging'); then * $data->hostname === "staging" * $data->db->connection === "database" * * The $options parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $options = array( * 'allowModifications' => false, * 'nestSeparator' => '->' * ); * * @param string $filename * @param string|null $section * @param boolean|array $options * @throws Zend_Config_Exception * @return void */ public function __construct($filename, $section = null, $options = false) { $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['nestSeparator'])) { $this->_nestSeparator = (string) $options['nestSeparator']; } } $this->_configIni = $this->parseIni($filename, true); $this->setupIniArray($this->_configIni); $this->putFileToCache($filename, $this->_configIni); foreach ($this->_configIni as $sectionName => $content) { $this->_configIni = $this->mergeExtends($sectionName, $this->_configIni); } $preProcessedArray = $this->_configIni; if (is_null($section)) { $dataArray = array(); foreach ($preProcessedArray as $sectionName => $sectionData) { $dataArray[$sectionName] = array(); foreach ($sectionData as $name => $value) { $dataArray[$sectionName] = $this->_processKey($name, $value, $dataArray[$sectionName]); } } } elseif (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($preProcessedArray[$sectionName])) { throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}"); } $dataArray[$sectionName] = array(); foreach ($preProcessedArray[$sectionName] as $name => $value) { $dataArray[$sectionName] = $this->_processKey($name, $value, $dataArray[$sectionName]); } } } else { if (!isset($preProcessedArray[$section])) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}"); } $dataArray[$section] = array(); foreach ($preProcessedArray[$section] as $name => $value) { $dataArray[$section] = $this->_processKey($name, $value, $dataArray[$sectionName]); } } parent::__construct($dataArray, $allowModifications); $this->_loadedSection = $section; }
/** * // * * @param array $options * @return void */ public function __construct(array $options = array()) { parent::__construct($options, true); }
/** * Loads the section $section from the config file (or string $xml for * access facilitated by nested object properties. * * Sections are defined in the XML as children of the root element. * * In order to extend another section, a section defines the "extends" * attribute having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "extends". * * @param string $xml XML file or string to process * @param mixed $section Section to process * @param boolean $options Whether modifications are allowed at runtime * @throws Zend_Config_Exception When xml is not set or cannot be loaded * @throws Zend_Config_Exception When section $sectionName cannot be found in $xml */ public function __construct($xml, $section = null, $options = false) { if (empty($xml)) { // require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['skipExtends'])) { $this->_skipExtends = (bool) $options['skipExtends']; } } set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed if (strstr($xml, '<?xml')) { $config = simplexml_load_string($xml); } else { $config = simplexml_load_file($xml); } restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { // require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } if ($section === null) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } else { if (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config->{$sectionName})) { // require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$xml}"); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config->{$section})) { // require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$xml}"); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // Section in the XML file contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } } $this->_loadedSection = $section; }
/** * This class mirrors Zend_Config_Ini with a few exceptions. Notably, * there is no need to parse dots in property names, and a bug has been * corrected where in values being set as properties on the object cause * an error when access is then attempted (since the __get function is * overwritten in the parent object), the fix for this being to store the * passed in options locally. * * Loads the section $section from the config file $filename for * access facilitated by nested object properties. * * If the section name contains a < then the section name to the right * is loaded and included into the properties. Note that the keys in * this $section will override any keys of the same * name in the sections that have been included via <. * * If the $section is null, then all sections in the yaml file are loaded. * * example yaml file: * production: * debug: false * db: * adapter: PDO_MYSQL * params: * host: someserver * username: wiz_user * password: "******" * dbname: system_wiz * nonesense: value * * staging < production: * debug: true * db: * params: * host: localhost * username: wiz * password: "******" * dbname: wiz * * after calling $data = new ZExt_Config_Yaml($file, 'staging'); then * $data->debug === true * $data->db->params->host === "localhost" * $data->db->params->nonesense === "value" * * The $options parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $options = array( * 'allowModifications' => false, * 'skipExtends' => false * ); * * @param string $filename * @param string|null $section * @param boolean|array $options * @throws Zend_Config_Exception * @return void */ public function __construct($filename, $section = null, $options = false) { // If filename is empy, we cannot proceed. if (empty($filename)) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } // if syck has not been loaded, we cannot proceeed. if (!function_exists('syck_load')) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Syck extension is not loaded'); } // check to see what options have been passed and store them $allowModifications = false; $this->_options = array(); if (is_bool($options)) { // boolean passed in for optins, so assume this is meant as the // allowModifications settings $allowModifications = $options; } elseif (is_array($options)) { // if options is an array, then collect several settings if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['skipExtends'])) { $this->_options['skipExtends'] = (bool) $options['skipExtends']; } } // If the yaml file cannot be read without errors, then we cannot proceed. // use error handler from the parent config object //set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed $ymlArray = syck_load(file_get_contents($filename)); //restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } // load and process the section requested by the "Section" variable (or return // all sections if no section specified) $preProcessedArray = array(); foreach ($ymlArray as $key => $data) { $bits = explode('<', $key); $thisSection = trim($bits[0]); switch (count($bits)) { // no parent section specified, so make no modification case 1: $preProcessedArray[$thisSection] = $data; break; // store the name of the parent section in a special array key AT THE TOP // of the array. // store the name of the parent section in a special array key AT THE TOP // of the array. case 2: $extendedSection = trim($bits[1]); $preProcessedArray[$thisSection] = array_merge(array(';extends' => $extendedSection), $data); break; default: // this cannot be! /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Section "' . $thisSection . '" may not extend multiple sections in $filename'); } } if (null === $section) { // if no section specified, then process and return all sections $dataArray = array(); foreach ($preProcessedArray as $sectionName => $sectionData) { if (!is_array($sectionData)) { $dataArray = array_merge_recursive($dataArray, array($sectionName => $sectionData)); } else { $dataArray[$sectionName] = $this->_processExtends($preProcessedArray, $sectionName); } } parent::__construct($dataArray, $allowModifications); } elseif (is_array($section)) { // if multiple sections specified, then return them $dataArray = array(); foreach ($section as $sectionName) { if (!isset($preProcessedArray[$sectionName])) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}"); } $processedArray = $this->_processExtends($preProcessedArray, $sectionName); $dataArray = $this->array_merge_recursive_distinct($processedArray, $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($preProcessedArray[$section])) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}"); } parent::__construct($this->_processExtends($preProcessedArray, $section), $allowModifications); } $this->_loadedSection = $section; }