summaryrefslogtreecommitdiff
path: root/ext/simplexml
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2012-07-07 12:50:03 -0700
committerStanislav Malyshev <stas@php.net>2012-07-07 12:51:26 -0700
commita213c10ef2125ac2da7a71ddb668d6f0aea8a05c (patch)
tree0507174df83c3a4f4d8778ced4807a28e78337b9 /ext/simplexml
parent79ed100c19667ecf8b8fcb445bd52bf8c22cee0a (diff)
parentf0df7dbc8f5d39260b9e230cf1db3c436e36dbad (diff)
downloadphp-git-a213c10ef2125ac2da7a71ddb668d6f0aea8a05c.tar.gz
Merge branch 'pull-request/112' into PHP-5.4
* pull-request/112: Added in NEWS and UPGRADING for feature 55218 Adding in test for feature 55218 Implements feature 55218
Diffstat (limited to 'ext/simplexml')
-rw-r--r--ext/simplexml/simplexml.c21
-rw-r--r--ext/simplexml/tests/feature55218.phpt117
2 files changed, 133 insertions, 5 deletions
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