Fixing XML class references

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6450 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-02-11 02:24:10 +00:00
parent 7f673226d7
commit 14523dc8c4
4 changed files with 53 additions and 36 deletions

View file

@ -795,7 +795,7 @@ class Set extends Object {
*/ */
function reverse($object) { function reverse($object) {
$out = array(); $out = array();
if (is_a($object, 'XMLNode')) { if (is_a($object, 'XmlNode')) {
if (isset($object->name) && isset($object->children)) { if (isset($object->name) && isset($object->children)) {
if ($object->name === '#document' && !empty($object->children)) { if ($object->name === '#document' && !empty($object->children)) {
$out = Set::reverse($object->children[0]); $out = Set::reverse($object->children[0]);

View file

@ -24,7 +24,7 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
uses('set'); App::import('Core', array('Xml', 'Set'));
/** /**
* XML Helper class for easy output of XML structures. * XML Helper class for easy output of XML structures.
@ -88,7 +88,7 @@ class XmlHelper extends AppHelper {
* @see XML::addNs() * @see XML::addNs()
*/ */
function addNs($name, $url = null) { function addNs($name, $url = null) {
return XML::addNs($name, $url); return Xml::addNamespace($name, $url);
} }
/** /**
* Removes a namespace added in addNs() * Removes a namespace added in addNs()
@ -98,7 +98,7 @@ class XmlHelper extends AppHelper {
* @see XML::removeNs() * @see XML::removeNs()
*/ */
function removeNs($name) { function removeNs($name) {
XML::removeNs($name); Xml::removeGlobalNamespace($name);
} }
/** /**
* Prepares the current set of namespaces for output in elem() / __composeAttributes() * Prepares the current set of namespaces for output in elem() / __composeAttributes()
@ -211,11 +211,8 @@ class XmlHelper extends AppHelper {
* @return string A copy of $data in XML format * @return string A copy of $data in XML format
*/ */
function serialize($data, $options = array()) { function serialize($data, $options = array()) {
if (!class_exists('XML') && !class_exists('xml')) {
App::import('Core', 'Xml');
}
$data = new Xml($data, array_merge(array('attributes' => false, 'format' => 'attributes'), $options)); $data = new Xml($data, array_merge(array('attributes' => false, 'format' => 'attributes'), $options));
return $data->toString(false); return $data->toString(array_merge(array('header' => false), $options));
} }
} }

View file

@ -514,7 +514,7 @@ class XmlNode extends Object {
function &document() { function &document() {
$document =& $this; $document =& $this;
while (true) { while (true) {
if (get_class($document) == 'XML' || $document == null) { if (get_class($document) == 'Xml' || $document == null) {
break; break;
} }
$document =& $document->parent(); $document =& $document->parent();
@ -628,7 +628,7 @@ class XmlNode extends Object {
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
* @since CakePHP v .0.10.3.1400 * @since CakePHP v .0.10.3.1400
*/ */
class XML extends XmlNode { class Xml extends XmlNode {
/** /**
* Resource handle to XML parser. * Resource handle to XML parser.
@ -755,7 +755,7 @@ class XML extends XmlNode {
* *
* @return boolean Success * @return boolean Success
* @access public * @access public
* @see XML::load() * @see Xml::load()
* @todo figure out how to link attributes and namespaces * @todo figure out how to link attributes and namespaces
*/ */
function parse() { function parse() {
@ -821,7 +821,7 @@ class XML extends XmlNode {
* @return string XML data * @return string XML data
* @access public * @access public
* @deprecated * @deprecated
* @see XML::toString() * @see Xml::toString()
*/ */
function compose($options = array()) { function compose($options = array()) {
return $this->toString($options); return $this->toString($options);
@ -891,8 +891,10 @@ class XML extends XmlNode {
* @return void * @return void
*/ */
function addNamespace($prefix, $url) { function addNamespace($prefix, $url) {
if ($ns = $this->__resolveNamespace($name, $url)) { $_this =& XmlManager::getInstance();
$this->namespaces = array_merge($this->namespaces, $ns);
if ($ns = XML::__resolveNamespace($prefix, $url)) {
$_this->namespaces = array_merge($_this->namespaces, $ns);
return true; return true;
} }
return false; return false;
@ -908,7 +910,7 @@ class XML extends XmlNode {
$options = array('header' => $options); $options = array('header' => $options);
} }
$defaults = array('header' => false, 'encoding' => $this->encoding); $defaults = array('header' => false, 'encoding' => $this->encoding);
$options = array_merge($defaults, XML::options(), $options); $options = array_merge($defaults, Xml::options(), $options);
$data = parent::toString($options, 0); $data = parent::toString($options, 0);
if ($options['header']) { if ($options['header']) {
@ -943,8 +945,8 @@ class XML extends XmlNode {
* @static * @static
*/ */
function addGlobalNs($name, $url = null) { function addGlobalNs($name, $url = null) {
$_this =& XMLManager::getInstance(); $_this =& XmlManager::getInstance();
if ($ns = XML::__resolveNamespace($name, $url)) { if ($ns = Xml::__resolveNamespace($name, $url)) {
$_this->__namespaces = array_merge($_this->__namespaces, $ns); $_this->__namespaces = array_merge($_this->__namespaces, $ns);
return true; return true;
} }
@ -959,6 +961,7 @@ class XML extends XmlNode {
* @access private * @access private
*/ */
function __resolveNamespace($name, $url) { function __resolveNamespace($name, $url) {
$_this =& XmlManager::getInstance();
if ($url == null && in_array($name, array_keys($_this->__defaultNamespaceMap))) { if ($url == null && in_array($name, array_keys($_this->__defaultNamespaceMap))) {
$url = $_this->__defaultNamespaceMap[$name]; $url = $_this->__defaultNamespaceMap[$name];
} elseif ($url == null) { } elseif ($url == null) {
@ -973,13 +976,13 @@ class XML extends XmlNode {
return array($name => $url); return array($name => $url);
} }
/** /**
* Alias to XML::addNs * Alias to Xml::addNs
* *
* @access public * @access public
* @static * @static
*/ */
function addGlobalNamespace($name, $url = null) { function addGlobalNamespace($name, $url = null) {
return XML::addGlobalNs($name, $url); return Xml::addGlobalNs($name, $url);
} }
/** /**
* Removes a namespace added in addNs() * Removes a namespace added in addNs()
@ -989,29 +992,29 @@ class XML extends XmlNode {
* @static * @static
*/ */
function removeGlobalNs($name) { function removeGlobalNs($name) {
$_this =& XMLManager::getInstance(); $_this =& XmlManager::getInstance();
if (in_array($name, array_keys($_this->__namespaces))) { if (in_array($name, array_keys($_this->namespaces))) {
unset($_this->__namespaces[$name]); unset($_this->namespaces[$name]);
} elseif (in_array($name, $_this->__namespaces)) { } elseif (in_array($name, $_this->namespaces)) {
$keys = array_keys($_this->__namespaces); $keys = array_keys($_this->namespaces);
$count = count($keys); $count = count($keys);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if ($_this->__namespaces[$keys[$i]] == $name) { if ($_this->namespaces[$keys[$i]] == $name) {
unset($_this->__namespaces[$keys[$i]]); unset($_this->namespaces[$keys[$i]]);
return; return;
} }
} }
} }
} }
/** /**
* Alias to XML::removeNs * Alias to Xml::removeNs
* *
* @access public * @access public
* @static * @static
*/ */
function removeGlobalNamespace($name, $url = null) { function removeGlobalNamespace($name, $url = null) {
XML::removeGlobalNs($name, $url); Xml::removeGlobalNs($name, $url);
} }
/** /**
* Sets/gets global XML options * Sets/gets global XML options
@ -1022,7 +1025,7 @@ class XML extends XmlNode {
* @static * @static
*/ */
function options($options = array()) { function options($options = array()) {
$_this =& XMLManager::getInstance(); $_this =& XmlManager::getInstance();
$_this->options = array_merge($_this->options, $options); $_this->options = array_merge($_this->options, $options);
return $_this->options; return $_this->options;
} }
@ -1129,7 +1132,7 @@ class XmlTextNode extends XmlNode {
} }
$defaults = array('cdata' => true, 'whitespace' => false, 'convertEntities' => false); $defaults = array('cdata' => true, 'whitespace' => false, 'convertEntities' => false);
$options = array_merge($defaults, XML::options(), $options); $options = array_merge($defaults, Xml::options(), $options);
$val = $this->value; $val = $this->value;
if ($options['convertEntities'] && function_exists('mb_convert_encoding')) { if ($options['convertEntities'] && function_exists('mb_convert_encoding')) {
@ -1154,7 +1157,7 @@ class XmlTextNode extends XmlNode {
* *
* @access private * @access private
*/ */
class XMLManager { class XmlManager {
/** /**
* Global XML namespaces. Used in all XML documents processed by this application * Global XML namespaces. Used in all XML documents processed by this application
@ -1198,7 +1201,7 @@ class XMLManager {
static $instance = array(); static $instance = array();
if (!isset($instance[0]) || !$instance[0]) { if (!isset($instance[0]) || !$instance[0]) {
$instance[0] =& new XMLManager(); $instance[0] =& new XmlManager();
} }
return $instance[0]; return $instance[0];
} }

View file

@ -40,14 +40,31 @@ uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.
*/ */
class XmlHelperTest extends UnitTestCase { class XmlHelperTest extends UnitTestCase {
function skip() {
$this->skipif (true, 'XmlHelper test not implemented');
}
function setUp() { function setUp() {
$this->Xml = new XmlHelper(); $this->Xml = new XmlHelper();
} }
function testAddNamespace() {
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml');
$this->assertEqual($manager->namespaces, $expected);
}
function testRemoveNamespace() {
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
$this->Xml->addNs('custom2', 'http://example.com/dtd2.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
$this->Xml->removeNs('custom');
$expected = array('custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
}
function tearDown() { function tearDown() {
unset($this->Xml); unset($this->Xml);
} }