import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -14,9 +14,9 @@
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @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: Xml.php 14665 2009-04-05 08:46:51Z rob $
|
||||
* @version $Id: Xml.php 17267 2009-07-29 02:13:18Z yoshida@zend.co.jp $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -29,18 +29,23 @@ require_once 'Zend/Config.php';
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @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_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/';
|
||||
|
||||
/**
|
||||
* Wether 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.
|
||||
@ -54,9 +59,9 @@ class Zend_Config_Xml extends Zend_Config
|
||||
* 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 $allowModifications Wether modifiacations are allowed at runtime
|
||||
* @param string $xml XML 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 xml is not set or cannot be loaded
|
||||
* @throws Zend_Config_Exception When section $sectionName cannot be found in $xml
|
||||
*/
|
||||
@ -78,7 +83,7 @@ class Zend_Config_Xml extends Zend_Config
|
||||
$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);
|
||||
@ -147,12 +152,13 @@ class Zend_Config_Xml extends Zend_Config
|
||||
throw new Zend_Config_Exception("Section '$section' cannot be found");
|
||||
}
|
||||
|
||||
$thisSection = $element->$section;
|
||||
$thisSection = $element->$section;
|
||||
$nsAttributes = $thisSection->attributes(self::XML_NAMESPACE);
|
||||
|
||||
if (isset($thisSection['extends'])) {
|
||||
$extendedSection = (string) $thisSection['extends'];
|
||||
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);
|
||||
}
|
||||
@ -172,7 +178,8 @@ class Zend_Config_Xml extends Zend_Config
|
||||
*/
|
||||
protected function _toArray(SimpleXMLElement $xmlObject)
|
||||
{
|
||||
$config = array();
|
||||
$config = array();
|
||||
$nsAttributes = $xmlObject->attributes(self::XML_NAMESPACE);
|
||||
|
||||
// Search for parent node values
|
||||
if (count($xmlObject->attributes()) > 0) {
|
||||
@ -195,10 +202,57 @@ class Zend_Config_Xml extends Zend_Config
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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();
|
||||
@ -221,7 +275,7 @@ class Zend_Config_Xml extends Zend_Config
|
||||
$config[$key] = $value;
|
||||
}
|
||||
}
|
||||
} else if (!isset($xmlObject['extends']) && (count($config) === 0)) {
|
||||
} 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;
|
||||
|
Reference in New Issue
Block a user