Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dom namespacenode improvement #6939

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ PHP_MINIT_FUNCTION(dom)
dom_register_prop_handler(&dom_node_prop_handlers, "textContent", sizeof("textContent")-1, dom_node_text_content_read, dom_node_text_content_write);
zend_hash_add_ptr(&classes, dom_node_class_entry->name, &dom_node_prop_handlers);

dom_namespace_node_class_entry = register_class_DOMNameSpaceNode();
dom_namespace_node_class_entry = register_class_DOMNameSpaceNode(dom_node_class_entry);
dom_namespace_node_class_entry->create_object = dom_objects_new;

zend_hash_init(&dom_namespace_node_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function removeChild(DOMNode $child) {}
public function replaceChild(DOMNode $node, DOMNode $child) {}
}

class DOMNameSpaceNode
class DOMNameSpaceNode extends DOMNode
{
}

Expand Down
6 changes: 3 additions & 3 deletions ext/dom/php_dom_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: c41e6d58eb8b0bbdb07401c4f1eb92c6ba3d324c */
* Stub hash: 9913983970c7a26ce1e6d71dc290d5eaab894643 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
Expand Down Expand Up @@ -908,12 +908,12 @@ static zend_class_entry *register_class_DOMNode(void)
return class_entry;
}

static zend_class_entry *register_class_DOMNameSpaceNode(void)
static zend_class_entry *register_class_DOMNameSpaceNode(zend_class_entry *class_entry_DOMNode)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "DOMNameSpaceNode", class_DOMNameSpaceNode_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry = zend_register_internal_class_ex(&ce, class_entry_DOMNode);

return class_entry;
}
Expand Down
57 changes: 57 additions & 0 deletions ext/dom/tests/domnamespacenodes.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
Namespace nodes: DOMNamespaceNode functionality
--EXTENSIONS--
dom
--FILE--
<?php
$xmlStr = <<<EOXML
<hello xmlns="http://www.hello.com" xmlns:foo="http://foo">
<item xmlns:bar="http://bar">A</item>
</hello>
EOXML;

$dom = new DOMDocument;
$dom->loadXML($xmlStr);
if(!$dom) {
echo "Error while parsing the document\n";
exit;
}

$node = $dom->documentElement;
$checkInstance = fn ($node): string =>
($node instanceof DOMNode && $node instanceof DOMNameSpaceNode) ? 'YES' : 'NO';


$xmlns = $node->getAttributeNode('xmlns');
echo "Root XMLNS uri: ".$xmlns->namespaceURI."\n";
echo "Root XMLNS prefix: ".$xmlns->prefix."\n";
echo "This is a node: " . $checkInstance($xmlns) . "\n";

$foo = $node->getAttributeNode('xmlns:foo');
echo "Root XMLNS:foo uri: ".$foo->namespaceURI."\n";
echo "Root XMLNS:foo prefix: ".$foo->prefix."\n";
echo "This is a node: " . $checkInstance($foo) . "\n";

$bar = $node->firstElementChild->getAttributeNode('xmlns:bar');
echo "Item XMLNS:bar uri: ".$bar->namespaceURI."\n";
echo "Item XMLNS:bar prefix: ".$bar->prefix."\n";
echo "This is a node: " . $checkInstance($bar) . "\n";

$node->firstElementChild->removeAttributeNS($bar->namespaceURI, $bar->prefix);

print $dom->saveXML($node);

?>
--EXPECT--
Root XMLNS uri: http://www.hello.com
Root XMLNS prefix:
This is a node: YES
Root XMLNS:foo uri: http://foo
Root XMLNS:foo prefix: foo
This is a node: YES
Item XMLNS:bar uri: http://bar
Item XMLNS:bar prefix: bar
This is a node: YES
<hello xmlns="http://www.hello.com" xmlns:foo="http://foo">
<item>A</item>
</hello>