summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rwxr-xr-xUPGRADING4
-rw-r--r--ext/simplexml/simplexml.c21
-rw-r--r--ext/simplexml/tests/feature55218.phpt117
4 files changed, 142 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 70a8eb9ec0..c1ad1837d8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+?? ??? 2012, PHP 5.4.6
+
+- SimpleXML:
+ . Implemented FR #55218 Get namespaces from current node. (Lonny)
+
?? ??? 2012, PHP 5.4.5
- Core:
diff --git a/UPGRADING b/UPGRADING
index a10dca991c..f3a9c3ee8d 100755
--- a/UPGRADING
+++ b/UPGRADING
@@ -343,6 +343,10 @@ PHP 5.4 UPGRADE NOTES
- Since 5.4.5, resourcebundle_create() accepts null for the first two arguments.
+- Since 5.4.6, SimpleXMLElement::getDocNamespaces() has and extra parameter which
+ allows for toggling if the list of namespaces starts from the document root
+ or from the node you call the method on
+
==============================
5. Changes to existing classes
==============================
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 455280fc74..7236b8a1b3 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1513,22 +1513,28 @@ static void sxe_add_registered_namespaces(php_sxe_object *sxe, xmlNodePtr node,
}
/* }}} */
-/* {{{ proto string SimpleXMLElement::getDocNamespaces([bool recursive])
+/* {{{ proto string SimpleXMLElement::getDocNamespaces([bool recursive [, bool from_root])
Return all namespaces registered with document */
SXE_METHOD(getDocNamespaces)
{
- zend_bool recursive = 0;
+ zend_bool recursive = 0, from_root = 1;
php_sxe_object *sxe;
+ xmlNodePtr node;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &recursive) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &recursive, &from_root) == FAILURE) {
return;
}
array_init(return_value);
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+ if(from_root){
+ node = xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr);
+ }else{
+ GET_NODE(sxe, node);
+ }
- sxe_add_registered_namespaces(sxe, xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr), recursive, return_value TSRMLS_CC);
+ sxe_add_registered_namespaces(sxe, node, recursive, return_value TSRMLS_CC);
}
/* }}} */
@@ -2518,6 +2524,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_getnamespaces, 0, 0, 0)
ZEND_ARG_INFO(0, recursve)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_getdocnamespaces, 0, 0, 0)
+ ZEND_ARG_INFO(0, recursve)
+ ZEND_ARG_INFO(0, from_root)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_children, 0, 0, 0)
ZEND_ARG_INFO(0, ns)
ZEND_ARG_INFO(0, is_prefix)
@@ -2586,7 +2597,7 @@ static const zend_function_entry sxe_functions[] = { /* {{{ */
SXE_ME(attributes, arginfo_simplexmlelement_children, ZEND_ACC_PUBLIC)
SXE_ME(children, arginfo_simplexmlelement_children, ZEND_ACC_PUBLIC)
SXE_ME(getNamespaces, arginfo_simplexmlelement_getnamespaces, ZEND_ACC_PUBLIC)
- SXE_ME(getDocNamespaces, arginfo_simplexmlelement_getnamespaces, ZEND_ACC_PUBLIC)
+ SXE_ME(getDocNamespaces, arginfo_simplexmlelement_getdocnamespaces, ZEND_ACC_PUBLIC)
SXE_ME(getName, arginfo_simplexmlelement__void, ZEND_ACC_PUBLIC)
SXE_ME(addChild, arginfo_simplexmlelement_addchild, ZEND_ACC_PUBLIC)
SXE_ME(addAttribute, arginfo_simplexmlelement_addchild, ZEND_ACC_PUBLIC)
diff --git a/ext/simplexml/tests/feature55218.phpt b/ext/simplexml/tests/feature55218.phpt
new file mode 100644
index 0000000000..25ea534376
--- /dev/null
+++ b/ext/simplexml/tests/feature55218.phpt
@@ -0,0 +1,117 @@
+--TEST--
+Bug #55218 getDocNamespaces from current element and not root
+--SKIPIF--
+<?php
+if (!extension_loaded("simplexml")) print "skip SimpleXML not present";
+if (!extension_loaded("libxml")) print "skip LibXML not present";
+?>
+--FILE--
+<?php
+
+$x = new SimpleXMLElement(
+'<?xml version="1.0" standalone="yes"?>
+<people xmlns:p="http://example.org/p" >
+ <person id="1" xmlns:t="http://example.org/t" >
+ <t:name>John Doe</t:name>
+ </person>
+ <person id="2">Susie Q. Public</person>
+ <o>
+ <p:div>jdslkfjsldk jskdfjsmlkjfkldjkjflskj kljfslkjf sldk</p:div>
+ </o>
+</people>');
+
+echo "getDocNamespaces\n";
+echo "\nBackwards Compatibility:\n";
+echo "recursion:\n";
+
+var_dump ( $x->getDocNamespaces(true) ) ;
+var_dump( $x->person[0]->getDocNamespaces(true) );
+var_dump( $x->person[1]->getDocNamespaces(true) );
+
+echo "\nnon recursive:\n";
+
+var_dump( $x->getDocNamespaces(false) );
+var_dump( $x->person[0]->getDocNamespaces(false) );
+var_dump( $x->person[1]->getDocNamespaces(false) );
+
+echo "\n\nUsing new 'from_root' bool set to false:\n";
+echo "recursion:\n";
+
+var_dump ( $x->getDocNamespaces(true, false) ) ;
+var_dump( $x->person[0]->getDocNamespaces(true, false) );
+var_dump( $x->person[1]->getDocNamespaces(true, false) );
+
+echo "\nnon recursive:\n";
+
+var_dump( $x->getDocNamespaces(false, false) );
+var_dump( $x->person[0]->getDocNamespaces(false, false) );
+var_dump( $x->person[1]->getDocNamespaces(false, false) );
+
+?>
+===DONE===
+--EXPECTF--
+getDocNamespaces
+
+Backwards Compatibility:
+recursion:
+array(2) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+ ["t"]=>
+ string(20) "http://example.org/t"
+}
+array(2) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+ ["t"]=>
+ string(20) "http://example.org/t"
+}
+array(2) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+ ["t"]=>
+ string(20) "http://example.org/t"
+}
+
+non recursive:
+array(1) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+}
+array(1) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+}
+array(1) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+}
+
+
+Using new 'from_root' bool set to false:
+recursion:
+array(2) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+ ["t"]=>
+ string(20) "http://example.org/t"
+}
+array(1) {
+ ["t"]=>
+ string(20) "http://example.org/t"
+}
+array(0) {
+}
+
+non recursive:
+array(1) {
+ ["p"]=>
+ string(20) "http://example.org/p"
+}
+array(1) {
+ ["t"]=>
+ string(20) "http://example.org/t"
+}
+array(0) {
+}
+===DONE=== \ No newline at end of file