diff options
author | Lukas Winkler <git@lw1.at> | 2019-09-10 03:16:27 +0300 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2019-09-10 03:16:27 +0300 |
commit | 14c4688dab2f9fa13115adeb30477a9fcab467c7 (patch) | |
tree | 4c8003d992c625e29d04df6a13437ab239248dd7 | |
parent | 9855f8c1aaa2e7af6725423ba047fdf54a821106 (diff) |
remove Zend Config (#14875)
-rw-r--r-- | libs/Zend/Config/Exception.php | 33 | ||||
-rw-r--r-- | libs/Zend/Config/Ini.php | 309 | ||||
-rw-r--r-- | libs/Zend/Config/Json.php | 240 | ||||
-rw-r--r-- | libs/Zend/Config/Writer.php | 101 | ||||
-rw-r--r-- | libs/Zend/Config/Writer/Array.php | 55 | ||||
-rw-r--r-- | libs/Zend/Config/Writer/FileAbstract.php | 134 | ||||
-rw-r--r-- | libs/Zend/Config/Writer/Ini.php | 193 | ||||
-rw-r--r-- | libs/Zend/Config/Writer/Json.php | 106 | ||||
-rw-r--r-- | libs/Zend/Config/Writer/Xml.php | 127 | ||||
-rw-r--r-- | libs/Zend/Config/Writer/Yaml.php | 144 | ||||
-rw-r--r-- | libs/Zend/Config/Xml.php | 296 | ||||
-rw-r--r-- | libs/Zend/Config/Yaml.php | 381 |
12 files changed, 0 insertions, 2119 deletions
diff --git a/libs/Zend/Config/Exception.php b/libs/Zend/Config/Exception.php deleted file mode 100644 index a32f222603..0000000000 --- a/libs/Zend/Config/Exception.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $ - */ - -/** - * @see Zend_Exception - */ -// require_once 'Zend/Exception.php'; - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Exception extends Zend_Exception {} diff --git a/libs/Zend/Config/Ini.php b/libs/Zend/Config/Ini.php deleted file mode 100644 index cd06ddccde..0000000000 --- a/libs/Zend/Config/Ini.php +++ /dev/null @@ -1,309 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ini.php 24045 2011-05-23 12:45:11Z rob $ - */ - - -/** - * @see Zend_Config - */ -// require_once 'Zend/Config.php'; - - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Ini extends Zend_Config -{ - /** - * String that separates nesting levels of configuration data identifiers - * - * @var string - */ - protected $_nestSeparator = '.'; - - /** - * String that separates the parent section name - * - * @var string - */ - protected $_sectionSeparator = ':'; - - /** - * Whether to skip extends or not - * - * @var boolean - */ - protected $_skipExtends = false; - - /** - * 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 three configuration - * directives that may be set. For example: - * - * $options = array( - * 'allowModifications' => false, - * 'nestSeparator' => ':', - * 'skipExtends' => false, - * ); - * - * @param string $filename - * @param mixed $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']; - } - if (isset($options['skipExtends'])) { - $this->_skipExtends = (bool) $options['skipExtends']; - } - } - - $iniArray = $this->_loadIniFile($filename); - - 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 $filename"); - } - $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray); - - } - parent::__construct($dataArray, $allowModifications); - } - - $this->_loadedSection = $section; - } - - /** - * Load the INI file from disk using parse_ini_file(). Use a private error - * handler to convert any loading errors into a Zend_Config_Exception - * - * @param string $filename - * @throws Zend_Config_Exception - * @return array - */ - protected function _parseIniFile($filename) - { - 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); - } - - return $iniArray; - } - - /** - * Load the ini file and preprocess the section separator (':' in the - * section name (that is used for section extension) so that the resultant - * array has the correct section names and the extension information is - * stored in a sub-key called ';extends'. We use ';extends' as this can - * never be a valid key name in an INI file that has been loaded using - * parse_ini_file(). - * - * @param string $filename - * @throws Zend_Config_Exception - * @return array - */ - protected function _loadIniFile($filename) - { - $loaded = $this->_parseIniFile($filename); - $iniArray = array(); - foreach ($loaded as $key => $data) - { - $pieces = explode($this->_sectionSeparator, $key); - $thisSection = trim($pieces[0]); - switch (count($pieces)) { - case 1: - $iniArray[$thisSection] = $data; - break; - - case 2: - $extendedSection = trim($pieces[1]); - $iniArray[$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"); - } - } - - return $iniArray; - } - - /** - * Process each element in the section and handle the ";extends" inheritance - * key. Passes control to _processKey() to handle the nest separator - * sub-property syntax that may be used within the key name. - * - * @param array $iniArray - * @param string $section - * @param array $config - * @throws Zend_Config_Exception - * @return array - */ - protected function _processSection($iniArray, $section, $config = array()) - { - $thisSection = $iniArray[$section]; - - foreach ($thisSection as $key => $value) { - if (strtolower($key) == ';extends') { - if (isset($iniArray[$value])) { - $this->_assertValidExtend($section, $value); - - if (!$this->_skipExtends) { - $config = $this->_processSection($iniArray, $value, $config); - } - } else { - /** - * @see Zend_Config_Exception - */ - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Parent section '$section' cannot be found"); - } - } else { - $config = $this->_processKey($config, $key, $value); - } - } - return $config; - } - - /** - * Assign the key's value to the property list. Handles the - * nest separator for sub-properties. - * - * @param array $config - * @param string $key - * @param string $value - * @throws Zend_Config_Exception - * @return array - */ - protected function _processKey($config, $key, $value) - { - if (strpos($key, $this->_nestSeparator) !== false) { - $pieces = explode($this->_nestSeparator, $key, 2); - if (strlen($pieces[0]) && strlen($pieces[1])) { - if (!isset($config[$pieces[0]])) { - if ($pieces[0] === '0' && !empty($config)) { - // convert the current values in $config into an array - $config = array($pieces[0] => $config); - } else { - $config[$pieces[0]] = array(); - } - } elseif (!is_array($config[$pieces[0]])) { - /** - * @see Zend_Config_Exception - */ - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists"); - } - $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value); - } else { - /** - * @see Zend_Config_Exception - */ - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Invalid key '$key'"); - } - } else { - $config[$key] = $value; - } - return $config; - } -} diff --git a/libs/Zend/Config/Json.php b/libs/Zend/Config/Json.php deleted file mode 100644 index b80a95becd..0000000000 --- a/libs/Zend/Config/Json.php +++ /dev/null @@ -1,240 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $ - */ - -/** - * @see Zend_Config - */ -// require_once 'Zend/Config.php'; - -/** - * @see Zend_Json - */ -// require_once 'Zend/Json.php'; - -/** - * JSON Adapter for Zend_Config - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Json extends Zend_Config -{ - /** - * Name of object key indicating section current section extends - */ - const EXTENDS_NAME = "_extends"; - - /** - * Whether or not to ignore constants in the JSON string - * - * Note: if you do not have constant names in quotations in your JSON - * string, they may lead to syntax errors when parsing. - * - * @var bool - */ - protected $_ignoreConstants = false; - - /** - * Whether to skip extends or not - * - * @var boolean - */ - protected $_skipExtends = false; - - /** - * 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 - $config = Zend_Json::decode($json); - - if (null === $config) { - // 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; - } - - /** - * Helper function to process each element in the section and handle - * the "_extends" inheritance attribute. - * - * @param array $data Data array to process - * @param string $section Section to process - * @param array $config Configuration which was parsed yet - * @throws Zend_Config_Exception When $section cannot be found - * @return array - */ - protected function _processExtends(array $data, $section, array $config = array()) - { - if (!isset($data[$section])) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); - } - - $thisSection = $data[$section]; - - if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) { - if (is_array($thisSection[self::EXTENDS_NAME])) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received'); - } - $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]); - - if (!$this->_skipExtends) { - $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config); - } - unset($thisSection[self::EXTENDS_NAME]); - } - - $config = $this->_arrayMergeRecursive($config, $thisSection); - - return $config; - } - - /** - * Replace any constants referenced in a string with their values - * - * @param string $value - * @return string - */ - protected function _replaceConstants($value) - { - foreach ($this->_getConstants() as $constant) { - if (strstr($value, $constant)) { - $value = str_replace($constant, constant($constant), $value); - } - } - return $value; - } - - /** - * Get (reverse) sorted list of defined constant names - * - * @return array - */ - protected function _getConstants() - { - $constants = array_keys(get_defined_constants()); - rsort($constants, SORT_STRING); - return $constants; - } -} diff --git a/libs/Zend/Config/Writer.php b/libs/Zend/Config/Writer.php deleted file mode 100644 index 689ec43c98..0000000000 --- a/libs/Zend/Config/Writer.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Writer.php 23953 2011-05-03 05:47:39Z ralph $ - */ - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -abstract class Zend_Config_Writer -{ - /** - * Option keys to skip when calling setOptions() - * - * @var array - */ - protected $_skipOptions = array( - 'options' - ); - - /** - * Config object to write - * - * @var Zend_Config - */ - protected $_config = null; - - /** - * Create a new adapter - * - * $options can only be passed as array or be omitted - * - * @param null|array $options - */ - public function __construct(array $options = null) - { - if (is_array($options)) { - $this->setOptions($options); - } - } - - /** - * Set options via a Zend_Config instance - * - * @param Zend_Config $config - * @return Zend_Config_Writer - */ - public function setConfig(Zend_Config $config) - { - $this->_config = $config; - - return $this; - } - - /** - * Set options via an array - * - * @param array $options - * @return Zend_Config_Writer - */ - public function setOptions(array $options) - { - foreach ($options as $key => $value) { - if (in_array(strtolower($key), $this->_skipOptions)) { - continue; - } - - $method = 'set' . ucfirst($key); - if (method_exists($this, $method)) { - $this->$method($value); - } - } - - return $this; - } - - /** - * Write a Zend_Config object to it's target - * - * @return void - */ - abstract public function write(); -} diff --git a/libs/Zend/Config/Writer/Array.php b/libs/Zend/Config/Writer/Array.php deleted file mode 100644 index 6871e1c2cc..0000000000 --- a/libs/Zend/Config/Writer/Array.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Array.php 23775 2011-03-01 17:25:24Z ralph $ - */ - -/** - * @see Zend_Config_Writer - */ -// require_once 'Zend/Config/Writer/FileAbstract.php'; - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Writer_Array extends Zend_Config_Writer_FileAbstract -{ - /** - * Render a Zend_Config into a PHP Array config string. - * - * @since 1.10 - * @return string - */ - public function render() - { - $data = $this->_config->toArray(); - $sectionName = $this->_config->getSectionName(); - - if (is_string($sectionName)) { - $data = array($sectionName => $data); - } - - $arrayString = "<?php\n" - . "return " . var_export($data, true) . ";\n"; - - return $arrayString; - } -} diff --git a/libs/Zend/Config/Writer/FileAbstract.php b/libs/Zend/Config/Writer/FileAbstract.php deleted file mode 100644 index 0c5b72ae9b..0000000000 --- a/libs/Zend/Config/Writer/FileAbstract.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @package Writer - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ - -// require_once "Zend/Config/Writer.php"; - -/** - * Abstract File Writer - * - * @category Zend - * @package Zend_package - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FileAbstract.php 23775 2011-03-01 17:25:24Z ralph $ - */ -class Zend_Config_Writer_FileAbstract extends Zend_Config_Writer -{ - /** - * Filename to write to - * - * @var string - */ - protected $_filename = null; - - /** - * Wether to exclusively lock the file or not - * - * @var boolean - */ - protected $_exclusiveLock = false; - - /** - * Set the target filename - * - * @param string $filename - * @return Zend_Config_Writer_Array - */ - public function setFilename($filename) - { - $this->_filename = $filename; - - return $this; - } - - /** - * Set wether to exclusively lock the file or not - * - * @param boolean $exclusiveLock - * @return Zend_Config_Writer_Array - */ - public function setExclusiveLock($exclusiveLock) - { - $this->_exclusiveLock = $exclusiveLock; - - return $this; - } - - /** - * Write configuration to file. - * - * @param string $filename - * @param Zend_Config $config - * @param bool $exclusiveLock - * @return void - */ - public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) - { - if ($filename !== null) { - $this->setFilename($filename); - } - - if ($config !== null) { - $this->setConfig($config); - } - - if ($exclusiveLock !== null) { - $this->setExclusiveLock($exclusiveLock); - } - - if ($this->_filename === null) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No filename was set'); - } - - if ($this->_config === null) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No config was set'); - } - - $configString = $this->render(); - - $flags = 0; - - if ($this->_exclusiveLock) { - $flags |= LOCK_EX; - } - - $result = @file_put_contents($this->_filename, $configString, $flags); - - if ($result === false) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); - } - } - - /** - * Render a Zend_Config into a config file string. - * - * @since 1.10 - * @todo For 2.0 this should be redone into an abstract method. - * @return string - */ - public function render() - { - return ""; - } -} diff --git a/libs/Zend/Config/Writer/Ini.php b/libs/Zend/Config/Writer/Ini.php deleted file mode 100644 index df3a0cf26c..0000000000 --- a/libs/Zend/Config/Writer/Ini.php +++ /dev/null @@ -1,193 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ini.php 23775 2011-03-01 17:25:24Z ralph $ - */ - -/** - * @see Zend_Config_Writer - */ -// require_once 'Zend/Config/Writer/FileAbstract.php'; - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Writer_Ini extends Zend_Config_Writer_FileAbstract -{ - /** - * String that separates nesting levels of configuration data identifiers - * - * @var string - */ - protected $_nestSeparator = '.'; - - /** - * If true the ini string is rendered in the global namespace without sections. - * - * @var bool - */ - protected $_renderWithoutSections = false; - - /** - * Set the nest separator - * - * @param string $filename - * @return Zend_Config_Writer_Ini - */ - public function setNestSeparator($separator) - { - $this->_nestSeparator = $separator; - - return $this; - } - - /** - * Set if rendering should occour without sections or not. - * - * If set to true, the INI file is rendered without sections completely - * into the global namespace of the INI file. - * - * @param bool $withoutSections - * @return Zend_Config_Writer_Ini - */ - public function setRenderWithoutSections($withoutSections=true) - { - $this->_renderWithoutSections = (bool)$withoutSections; - return $this; - } - - /** - * Render a Zend_Config into a INI config string. - * - * @since 1.10 - * @return string - */ - public function render() - { - $iniString = ''; - $extends = $this->_config->getExtends(); - $sectionName = $this->_config->getSectionName(); - - if($this->_renderWithoutSections == true) { - $iniString .= $this->_addBranch($this->_config); - } else if (is_string($sectionName)) { - $iniString .= '[' . $sectionName . ']' . "\n" - . $this->_addBranch($this->_config) - . "\n"; - } else { - $config = $this->_sortRootElements($this->_config); - foreach ($config as $sectionName => $data) { - if (!($data instanceof Zend_Config)) { - $iniString .= $sectionName - . ' = ' - . $this->_prepareValue($data) - . "\n"; - } else { - if (isset($extends[$sectionName])) { - $sectionName .= ' : ' . $extends[$sectionName]; - } - - $iniString .= '[' . $sectionName . ']' . "\n" - . $this->_addBranch($data) - . "\n"; - } - } - } - - return $iniString; - } - - /** - * Add a branch to an INI string recursively - * - * @param Zend_Config $config - * @return void - */ - protected function _addBranch(Zend_Config $config, $parents = array()) - { - $iniString = ''; - - foreach ($config as $key => $value) { - $group = array_merge($parents, array($key)); - - if ($value instanceof Zend_Config) { - $iniString .= $this->_addBranch($value, $group); - } else { - $iniString .= implode($this->_nestSeparator, $group) - . ' = ' - . $this->_prepareValue($value) - . "\n"; - } - } - - return $iniString; - } - - /** - * Prepare a value for INI - * - * @param mixed $value - * @return string - */ - protected function _prepareValue($value) - { - if (is_integer($value) || is_float($value)) { - return $value; - } elseif (is_bool($value)) { - return ($value ? 'true' : 'false'); - } elseif (strpos($value, '"') === false) { - return '"' . $value . '"'; - } else { - /** @see Zend_Config_Exception */ - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Value can not contain double quotes "'); - } - } - - /** - * Root elements that are not assigned to any section needs to be - * on the top of config. - * - * @see http://framework.zend.com/issues/browse/ZF-6289 - * @param Zend_Config - * @return Zend_Config - */ - protected function _sortRootElements(Zend_Config $config) - { - $configArray = $config->toArray(); - $sections = array(); - - // remove sections from config array - foreach ($configArray as $key => $value) { - if (is_array($value)) { - $sections[$key] = $value; - unset($configArray[$key]); - } - } - - // readd sections to the end - foreach ($sections as $key => $value) { - $configArray[$key] = $value; - } - - return new Zend_Config($configArray); - } -} diff --git a/libs/Zend/Config/Writer/Json.php b/libs/Zend/Config/Writer/Json.php deleted file mode 100644 index 5140749f8d..0000000000 --- a/libs/Zend/Config/Writer/Json.php +++ /dev/null @@ -1,106 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $ - */ - -/** - * @see Zend_Config_Writer - */ -// require_once 'Zend/Config/Writer/FileAbstract.php'; - -/** - * @see Zend_Config_Json - */ -// require_once 'Zend/Config/Json.php'; - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Writer_Json extends Zend_Config_Writer_FileAbstract -{ - /** - * If we need to pretty-print JSON data - * - * @var boolean - */ - protected $_prettyPrint = false; - - /** - * Get prettyPrint flag - * - * @return the prettyPrint flag - */ - public function prettyPrint() - { - return $this->_prettyPrint; - } - - /** - * Set prettyPrint flag - * - * @param bool $prettyPrint PrettyPrint flag - * @return Zend_Config_Writer_Json - */ - public function setPrettyPrint($flag) - { - $this->_prettyPrint = (bool) $flag; - return $this; - } - - /** - * Render a Zend_Config into a JSON config string. - * - * @since 1.10 - * @return string - */ - public function render() - { - $data = $this->_config->toArray(); - $sectionName = $this->_config->getSectionName(); - $extends = $this->_config->getExtends(); - - if (is_string($sectionName)) { - $data = array($sectionName => $data); - } - - foreach ($extends as $section => $parentSection) { - $data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection; - } - - // Ensure that each "extends" section actually exists - foreach ($data as $section => $sectionData) { - if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) { - $sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME]; - if (!isset($data[$sectionExtends])) { - // Remove "extends" declaration if section does not exist - unset($data[$section][Zend_Config_Json::EXTENDS_NAME]); - } - } - } - - $out = Zend_Json::encode($data); - if ($this->prettyPrint()) { - $out = Zend_Json::prettyPrint($out); - } - return $out; - } -} diff --git a/libs/Zend/Config/Writer/Xml.php b/libs/Zend/Config/Writer/Xml.php deleted file mode 100644 index e44167119d..0000000000 --- a/libs/Zend/Config/Writer/Xml.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Xml.php 23775 2011-03-01 17:25:24Z ralph $ - */ - -/** - * @see Zend_Config_Writer - */ -// require_once 'Zend/Config/Writer/FileAbstract.php'; - -/** - * @see Zend_Config_Xml - */ -// require_once 'Zend/Config/Xml.php'; - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Writer_Xml extends Zend_Config_Writer_FileAbstract -{ - /** - * Render a Zend_Config into a XML config string. - * - * @since 1.10 - * @return string - */ - public function render() - { - $xml = new SimpleXMLElement('<zend-config xmlns:zf="' . Zend_Config_Xml::XML_NAMESPACE . '"/>'); - $extends = $this->_config->getExtends(); - $sectionName = $this->_config->getSectionName(); - - if (is_string($sectionName)) { - $child = $xml->addChild($sectionName); - - $this->_addBranch($this->_config, $child, $xml); - } else { - foreach ($this->_config as $sectionName => $data) { - if (!($data instanceof Zend_Config)) { - $xml->addChild($sectionName, (string) $data); - } else { - $child = $xml->addChild($sectionName); - - if (isset($extends[$sectionName])) { - $child->addAttribute('zf:extends', $extends[$sectionName], Zend_Config_Xml::XML_NAMESPACE); - } - - $this->_addBranch($data, $child, $xml); - } - } - } - - $dom = dom_import_simplexml($xml)->ownerDocument; - $dom->formatOutput = true; - - $xmlString = $dom->saveXML(); - - return $xmlString; - } - - /** - * Add a branch to an XML object recursively - * - * @param Zend_Config $config - * @param SimpleXMLElement $xml - * @param SimpleXMLElement $parent - * @return void - */ - protected function _addBranch(Zend_Config $config, SimpleXMLElement $xml, SimpleXMLElement $parent) - { - $branchType = null; - - foreach ($config as $key => $value) { - if ($branchType === null) { - if (is_numeric($key)) { - $branchType = 'numeric'; - $branchName = $xml->getName(); - $xml = $parent; - - unset($parent->{$branchName}); - } else { - $branchType = 'string'; - } - } else if ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Mixing of string and numeric keys is not allowed'); - } - - if ($branchType === 'numeric') { - if ($value instanceof Zend_Config) { - $child = $parent->addChild($branchName); - - $this->_addBranch($value, $child, $parent); - } else { - $parent->addChild($branchName, (string) $value); - } - } else { - if ($value instanceof Zend_Config) { - $child = $xml->addChild($key); - - $this->_addBranch($value, $child, $xml); - } else { - $xml->addChild($key, (string) $value); - } - } - } - } -} diff --git a/libs/Zend/Config/Writer/Yaml.php b/libs/Zend/Config/Writer/Yaml.php deleted file mode 100644 index c97b07b5ef..0000000000 --- a/libs/Zend/Config/Writer/Yaml.php +++ /dev/null @@ -1,144 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Yaml.php 23651 2011-01-21 21:51:00Z mikaelkael $ - */ - -/** - * @see Zend_Config_Writer - */ -// require_once 'Zend/Config/Writer/FileAbstract.php'; - -/** - * @see Zend_Config_Yaml - */ -// require_once 'Zend/Config/Yaml.php'; - -/** - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Writer_Yaml extends Zend_Config_Writer_FileAbstract -{ - /** - * What to call when we need to decode some YAML? - * - * @var callable - */ - protected $_yamlEncoder = array('Zend_Config_Writer_Yaml', 'encode'); - - /** - * Get callback for decoding YAML - * - * @return callable - */ - public function getYamlEncoder() - { - return $this->_yamlEncoder; - } - - /** - * Set callback for decoding YAML - * - * @param callable $yamlEncoder the decoder to set - * @return Zend_Config_Yaml - */ - public function setYamlEncoder($yamlEncoder) - { - if (!is_callable($yamlEncoder)) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Invalid parameter to setYamlEncoder - must be callable'); - } - - $this->_yamlEncoder = $yamlEncoder; - return $this; - } - - /** - * Render a Zend_Config into a YAML config string. - * - * @since 1.10 - * @return string - */ - public function render() - { - $data = $this->_config->toArray(); - $sectionName = $this->_config->getSectionName(); - $extends = $this->_config->getExtends(); - - if (is_string($sectionName)) { - $data = array($sectionName => $data); - } - - foreach ($extends as $section => $parentSection) { - $data[$section][Zend_Config_Yaml::EXTENDS_NAME] = $parentSection; - } - - // Ensure that each "extends" section actually exists - foreach ($data as $section => $sectionData) { - if (is_array($sectionData) && isset($sectionData[Zend_Config_Yaml::EXTENDS_NAME])) { - $sectionExtends = $sectionData[Zend_Config_Yaml::EXTENDS_NAME]; - if (!isset($data[$sectionExtends])) { - // Remove "extends" declaration if section does not exist - unset($data[$section][Zend_Config_Yaml::EXTENDS_NAME]); - } - } - } - - return call_user_func($this->getYamlEncoder(), $data); - } - - /** - * Very dumb YAML encoder - * - * Until we have Zend_Yaml... - * - * @param array $data YAML data - * @return string - */ - public static function encode($data) - { - return self::_encodeYaml(0, $data); - } - - /** - * Service function for encoding YAML - * - * @param int $indent Current indent level - * @param array $data Data to encode - * @return string - */ - protected static function _encodeYaml($indent, $data) - { - reset($data); - $result = ""; - $numeric = is_numeric(key($data)); - - foreach($data as $key => $value) { - if(is_array($value)) { - $encoded = "\n".self::_encodeYaml($indent+1, $value); - } else { - $encoded = (string)$value."\n"; - } - $result .= str_repeat(" ", $indent).($numeric?"- ":"$key: ").$encoded; - } - return $result; - } -} diff --git a/libs/Zend/Config/Xml.php b/libs/Zend/Config/Xml.php deleted file mode 100644 index 1819276ddd..0000000000 --- a/libs/Zend/Config/Xml.php +++ /dev/null @@ -1,296 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Xml.php 24045 2011-05-23 12:45:11Z rob $ - */ - -/** - * @see Zend_Config - */ -// require_once 'Zend/Config.php'; - -/** - * XML Adapter for Zend_Config - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Xml extends Zend_Config -{ - /** - * XML namespace for ZF-related tags and attributes - */ - const XML_NAMESPACE = 'http://framework.zend.com/xml/zend-config-xml/1.0/'; - - /** - * Whether to skip extends or not - * - * @var boolean - */ - protected $_skipExtends = false; - - /** - * 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". - * - * 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 $xml XML file or string to process - * @param mixed $section Section to process - * @param array|boolean $options - * @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; - } - - /** - * Helper function to process each element in the section and handle - * the "extends" inheritance attribute. - * - * @param SimpleXMLElement $element XML Element to process - * @param string $section Section to process - * @param array $config Configuration which was parsed yet - * @throws Zend_Config_Exception When $section cannot be found - * @return array - */ - protected function _processExtends(SimpleXMLElement $element, $section, array $config = array()) - { - if (!isset($element->$section)) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Section '$section' cannot be found"); - } - - $thisSection = $element->$section; - $nsAttributes = $thisSection->attributes(self::XML_NAMESPACE); - - if (isset($thisSection['extends']) || isset($nsAttributes['extends'])) { - $extendedSection = (string) (isset($nsAttributes['extends']) ? $nsAttributes['extends'] : $thisSection['extends']); - $this->_assertValidExtend($section, $extendedSection); - - if (!$this->_skipExtends) { - $config = $this->_processExtends($element, $extendedSection, $config); - } - } - - $config = $this->_arrayMergeRecursive($config, $this->_toArray($thisSection)); - - return $config; - } - - /** - * Returns a string or an associative and possibly multidimensional array from - * a SimpleXMLElement. - * - * @param SimpleXMLElement $xmlObject Convert a SimpleXMLElement into an array - * @return array|string - */ - protected function _toArray(SimpleXMLElement $xmlObject) - { - $config = array(); - $nsAttributes = $xmlObject->attributes(self::XML_NAMESPACE); - - // Search for parent node values - if (count($xmlObject->attributes()) > 0) { - foreach ($xmlObject->attributes() as $key => $value) { - if ($key === 'extends') { - continue; - } - - $value = (string) $value; - - if (array_key_exists($key, $config)) { - if (!is_array($config[$key])) { - $config[$key] = array($config[$key]); - } - - $config[$key][] = $value; - } else { - $config[$key] = $value; - } - } - } - - // Search for local 'const' nodes and replace them - if (count($xmlObject->children(self::XML_NAMESPACE)) > 0) { - if (count($xmlObject->children()) > 0) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("A node with a 'const' childnode may not have any other children"); - } - - $dom = dom_import_simplexml($xmlObject); - $namespaceChildNodes = array(); - - // We have to store them in an array, as replacing nodes will - // confuse the DOMNodeList later - foreach ($dom->childNodes as $node) { - if ($node instanceof DOMElement && $node->namespaceURI === self::XML_NAMESPACE) { - $namespaceChildNodes[] = $node; - } - } - - foreach ($namespaceChildNodes as $node) { - switch ($node->localName) { - case 'const': - if (!$node->hasAttributeNS(self::XML_NAMESPACE, 'name')) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Misssing 'name' attribute in 'const' node"); - } - - $constantName = $node->getAttributeNS(self::XML_NAMESPACE, 'name'); - - if (!defined($constantName)) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Constant with name '$constantName' was not defined"); - } - - $constantValue = constant($constantName); - - $dom->replaceChild($dom->ownerDocument->createTextNode($constantValue), $node); - break; - - default: - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception("Unknown node with name '$node->localName' found"); - } - } - - return (string) simplexml_import_dom($dom); - } - - // Search for children - if (count($xmlObject->children()) > 0) { - foreach ($xmlObject->children() as $key => $value) { - if (count($value->children()) > 0 || count($value->children(self::XML_NAMESPACE)) > 0) { - $value = $this->_toArray($value); - } else if (count($value->attributes()) > 0) { - $attributes = $value->attributes(); - if (isset($attributes['value'])) { - $value = (string) $attributes['value']; - } else { - $value = $this->_toArray($value); - } - } else { - $value = (string) $value; - } - - if (array_key_exists($key, $config)) { - if (!is_array($config[$key]) || !array_key_exists(0, $config[$key])) { - $config[$key] = array($config[$key]); - } - - $config[$key][] = $value; - } else { - $config[$key] = $value; - } - } - } else if (!isset($xmlObject['extends']) && !isset($nsAttributes['extends']) && (count($config) === 0)) { - // Object has no children nor attributes and doesn't use the extends - // attribute: it's a string - $config = (string) $xmlObject; - } - - return $config; - } -} diff --git a/libs/Zend/Config/Yaml.php b/libs/Zend/Config/Yaml.php deleted file mode 100644 index bda81d0565..0000000000 --- a/libs/Zend/Config/Yaml.php +++ /dev/null @@ -1,381 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@zend.com so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Yaml.php 24092 2011-05-31 02:43:28Z adamlundrigan $ - */ - -/** - * @see Zend_Config - */ -// require_once 'Zend/Config.php'; - -/** - * YAML Adapter for Zend_Config - * - * @category Zend - * @package Zend_Config - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Config_Yaml extends Zend_Config -{ - /** - * Attribute name that indicates what section a config extends from - */ - const EXTENDS_NAME = "_extends"; - - /** - * Whether to skip extends or not - * - * @var boolean - */ - protected $_skipExtends = false; - - /** - * What to call when we need to decode some YAML? - * - * @var callable - */ - protected $_yamlDecoder = array(__CLASS__, 'decode'); - - /** - * Whether or not to ignore constants in parsed YAML - * @var bool - */ - protected static $_ignoreConstants = false; - - /** - * Indicate whether parser should ignore constants or not - * - * @param bool $flag - * @return void - */ - public static function setIgnoreConstants($flag) - { - self::$_ignoreConstants = (bool) $flag; - } - - /** - * Whether parser should ignore constants or not - * - * @return bool - */ - public static function ignoreConstants() - { - return self::$_ignoreConstants; - } - - /** - * Get callback for decoding YAML - * - * @return callable - */ - public function getYamlDecoder() - { - return $this->_yamlDecoder; - } - - /** - * Set callback for decoding YAML - * - * @param callable $yamlDecoder the decoder to set - * @return Zend_Config_Yaml - */ - public function setYamlDecoder($yamlDecoder) - { - if (!is_callable($yamlDecoder)) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Invalid parameter to setYamlDecoder() - must be callable'); - } - - $this->_yamlDecoder = $yamlDecoder; - return $this; - } - - /** - * 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; - } - - /** - * Helper function to process each element in the section and handle - * the "_extends" inheritance attribute. - * - * @param array $data Data array to process - * @param string $section Section to process - * @param array $config Configuration which was parsed yet - * @return array - * @throws Zend_Config_Exception When $section cannot be found - */ - protected function _processExtends(array $data, $section, array $config = array()) - { - if (!isset($data[$section])) { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); - } - - $thisSection = $data[$section]; - - if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) { - $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]); - - if (!$this->_skipExtends) { - $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config); - } - unset($thisSection[self::EXTENDS_NAME]); - } - - $config = $this->_arrayMergeRecursive($config, $thisSection); - - return $config; - } - - /** - * Very dumb YAML parser - * - * Until we have Zend_Yaml... - * - * @param string $yaml YAML source - * @return array Decoded data - */ - public static function decode($yaml) - { - $lines = explode("\n", $yaml); - reset($lines); - return self::_decodeYaml(0, $lines); - } - - /** - * Service function to decode YAML - * - * @param int $currentIndent Current indent level - * @param array $lines YAML lines - * @return array|string - */ - protected static function _decodeYaml($currentIndent, &$lines) - { - $config = array(); - $inIndent = false; - while (list($n, $line) = each($lines)) { - $lineno = $n + 1; - - $line = rtrim(preg_replace("/#.*$/", "", $line)); - if (strlen($line) == 0) { - continue; - } - - $indent = strspn($line, " "); - - // line without the spaces - $line = trim($line); - if (strlen($line) == 0) { - continue; - } - - if ($indent < $currentIndent) { - // this level is done - prev($lines); - return $config; - } - - if (!$inIndent) { - $currentIndent = $indent; - $inIndent = true; - } - - if (preg_match("/(\w+):\s*(.*)/", $line, $m)) { - // key: value - if (strlen($m[2])) { - // simple key: value - $value = rtrim(preg_replace("/#.*$/", "", $m[2])); - // Check for booleans and constants - if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) { - $value = true; - } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) { - $value = false; - } elseif (!self::$_ignoreConstants) { - // test for constants - $value = self::_replaceConstants($value); - } - } else { - // key: and then values on new lines - $value = self::_decodeYaml($currentIndent + 1, $lines); - if (is_array($value) && !count($value)) { - $value = ""; - } - } - $config[$m[1]] = $value; - } elseif ($line[0] == "-") { - // item in the list: - // - FOO - if (strlen($line) > 2) { - $config[] = substr($line, 2); - } else { - $config[] = self::_decodeYaml($currentIndent + 1, $lines); - } - } else { - // require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception(sprintf( - 'Error parsing YAML at line %d - unsupported syntax: "%s"', - $lineno, $line - )); - } - } - return $config; - } - - /** - * Replace any constants referenced in a string with their values - * - * @param string $value - * @return string - */ - protected static function _replaceConstants($value) - { - foreach (self::_getConstants() as $constant) { - if (strstr($value, $constant)) { - $value = str_replace($constant, constant($constant), $value); - } - } - return $value; - } - - /** - * Get (reverse) sorted list of defined constant names - * - * @return array - */ - protected static function _getConstants() - { - $constants = array_keys(get_defined_constants()); - rsort($constants, SORT_STRING); - return $constants; - } -} |