import v1.0.0-RC4 | 2009-05-20

This commit is contained in:
2019-07-17 22:08:50 +02:00
commit b484e522e8
2459 changed files with 1038434 additions and 0 deletions

View File

@ -0,0 +1,32 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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 {}

254
libs/Zend/Config/Ini.php Normal file
View File

@ -0,0 +1,254 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ini.php 11206 2008-09-03 14:36:32Z ralph $
*/
/**
* @see Zend_Config
*/
require_once 'Zend/Config.php';
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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 = '.';
/**
* 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;
}
/**
* Helper function to process each element in the section and handle
* the "extends" inheritance keyword. Passes control to _processKey()
* to handle the "dot" sub-property syntax in each key.
*
* @param array $iniArray
* @param string $section
* @param array $config
* @throws Zend_Config_Exception
* @return array
*/
protected function _processExtends($iniArray, $section, $config = array())
{
$thisSection = $iniArray[$section];
foreach ($thisSection as $key => $value) {
if (strtolower($key) == ';extends') {
if (isset($iniArray[$value])) {
$this->_assertValidExtend($section, $value);
$config = $this->_processExtends($iniArray, $value, $config);
} else {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$section' cannot be found");
}
} else {
$config = $this->_processKey($config, $key, $value);
}
}
return $config;
}
/**
* Assign the key's value to the property list. Handle the "dot"
* notation for sub-properties by passing control to
* processLevelsInKey().
*
* @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]])) {
$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;
}
}

101
libs/Zend/Config/Writer.php Normal file
View File

@ -0,0 +1,101 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Writer.php 12220 2008-10-31 20:13:55Z dasprid $
*/
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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();
}

View File

@ -0,0 +1,101 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Array.php 12221 2008-10-31 20:32:43Z dasprid $
*/
/**
* @see Zend_Config_Writer
*/
require_once 'Zend/Config/Writer.php';
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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
{
/**
* Filename to write to
*
* @var string
*/
protected $_filename = null;
/**
* Set the target filename
*
* @param string $filename
* @return Zend_Config_Writer_Array
*/
public function setFilename($filename)
{
$this->_filename = $filename;
return $this;
}
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
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');
}
$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";
$result = @file_put_contents($this->_filename, $arrayString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
}

View File

@ -0,0 +1,174 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ini.php 12221 2008-10-31 20:32:43Z dasprid $
*/
/**
* @see Zend_Config_Writer
*/
require_once 'Zend/Config/Writer.php';
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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
{
/**
* Filename to write to
*
* @var string
*/
protected $_filename = null;
/**
* String that separates nesting levels of configuration data identifiers
*
* @var string
*/
protected $_nestSeparator = '.';
/**
* Set the target filename
*
* @param string $filename
* @return Zend_Config_Writer_Xml
*/
public function setFilename($filename)
{
$this->_filename = $filename;
return $this;
}
/**
* Set the nest separator
*
* @param string $filename
* @return Zend_Config_Writer_Ini
*/
public function setNestSeparator($separator)
{
$this->_nestSeparator = $separator;
return $this;
}
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
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');
}
$iniString = '';
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$iniString .= '[' . $sectionName . ']' . "\n"
. $this->_addBranch($this->_config)
. "\n";
} else {
foreach ($this->_config as $sectionName => $data) {
if (isset($extends[$sectionName])) {
$sectionName .= ' : ' . $extends[$sectionName];
}
$iniString .= '[' . $sectionName . ']' . "\n"
. $this->_addBranch($data)
. "\n";
}
}
$result = @file_put_contents($this->_filename, $iniString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
/**
* 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');
} else {
return '"' . addslashes($value) . '"';
}
}
}

View File

@ -0,0 +1,140 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Xml.php 12221 2008-10-31 20:32:43Z dasprid $
*/
/**
* @see Zend_Config_Writer
*/
require_once 'Zend/Config/Writer.php';
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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
{
/**
* Filename to write to
*
* @var string
*/
protected $_filename = null;
/**
* Set the target filename
*
* @param string $filename
* @return Zend_Config_Writer_Xml
*/
public function setFilename($filename)
{
$this->_filename = $filename;
return $this;
}
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
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');
}
$xml = new SimpleXMLElement('<zend-config/>');
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$child = $xml->addChild($sectionName);
$this->_addBranch($this->_config, $child);
} else {
foreach ($this->_config as $sectionName => $data) {
if (!($data instanceof Zend_Config)) {
continue;
}
$child = $xml->addChild($sectionName);
if (isset($extends[$sectionName])) {
$child->addAttribute('extends', $extends[$sectionName]);
}
$this->_addBranch($data, $child);
}
}
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
$xmlString = $dom->saveXML();
$result = @file_put_contents($this->_filename, $xmlString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
/**
* Add a branch to an XML object recursively
*
* @param Zend_Config $config
* @param SimpleXMLElement $xml
* @return void
*/
protected function _addBranch(Zend_Config $config, SimpleXMLElement $xml)
{
foreach ($config as $key => $value) {
if ($value instanceof Zend_Config) {
$child = $xml->addChild($key);
$this->_addBranch($value, $child);
} else {
$xml->addChild($key, (string) $value);
}
}
}
}

230
libs/Zend/Config/Xml.php Normal file
View File

@ -0,0 +1,230 @@
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Xml.php 11427 2008-09-18 16:11:43Z doctorrock83 $
*/
/**
* @see Zend_Config
*/
require_once 'Zend/Config.php';
/**
* XML Adapter for Zend_Config
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 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
{
/**
* 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 File to process
* @param mixed $section Section to process
* @param boolean $allowModifications Wether modifiacations are allowed at runtime
* @throws Zend_Config_Exception When filename is not set
* @throws Zend_Config_Exception When section $sectionName cannot be found in $filename
*/
public function __construct($filename, $section = null, $allowModifications = false)
{
if (empty($filename)) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Filename is not set');
}
set_error_handler(array($this, '_loadFileErrorHandler'));
$config = simplexml_load_file($filename); // Warnings and errors are suppressed
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 $filename");
}
$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 $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;
}
/**
* 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;
if (isset($thisSection['extends'])) {
$extendedSection = (string) $thisSection['extends'];
$this->_assertValidExtend($section, $extendedSection);
$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();
// 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 children
if (count($xmlObject->children()) > 0) {
foreach ($xmlObject->children() as $key => $value) {
if (count($value->children()) > 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']) && (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;
}
/**
* Merge two arrays recursively, overwriting keys of the same name
* in $array1 with the value in $array2.
*
* @param mixed $firstArray First array
* @param mixed $secondArray Second array to merge into first array
* @return array
*/
protected function _arrayMergeRecursive($firstArray, $secondArray)
{
if (is_array($firstArray) && is_array($secondArray)) {
foreach ($secondArray as $key => $value) {
if (isset($firstArray[$key])) {
$firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
} else {
$firstArray[$key] = $value;
}
}
} else {
$firstArray = $secondArray;
}
return $firstArray;
}
}