From d4f57cbe3e08cb28cc7f93f86a90212c3a8724f5 Mon Sep 17 00:00:00 2001 From: Paul Tarjan Date: Tue, 21 May 2013 15:27:29 -0700 Subject: [PATCH] add dom_import_simplexml Needed for Symphony. We are labelling the dom extension as unsupported, is that still correct @sgolemon? The iffiest part of the diff is new-ing up the ##c_DOMDocument##. Is that right? --- hphp/idl/domdocument.idl.json | 20 ++++++++++++++++++- hphp/runtime/ext/ext_domdocument.cpp | 15 ++++++++++++++ hphp/runtime/ext/ext_domdocument.h | 1 + hphp/system/class_map.cpp | 6 ++++++ hphp/system/lib/systemlib.cpp | 5 +++++ hphp/system/lib/systemlib.h | 3 +++ .../slow/simple_xml/dom_import_simplexml.php | 7 +++++++ .../dom_import_simplexml.php.expect | 2 ++ 8 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 hphp/test/slow/simple_xml/dom_import_simplexml.php create mode 100644 hphp/test/slow/simple_xml/dom_import_simplexml.php.expect diff --git a/hphp/idl/domdocument.idl.json b/hphp/idl/domdocument.idl.json index 37afffcd8..5eabb3f66 100644 --- a/hphp/idl/domdocument.idl.json +++ b/hphp/idl/domdocument.idl.json @@ -1508,6 +1508,24 @@ "value": "null" } ] + }, + { + "name": "dom_import_simplexml", + "desc": "This function takes the node node of class SimpleXML and makes it into a DOMElement node. This new object can then be used as a native DOMElement node.", + "flags": [ + "HasDocComment" + ], + "return": { + "type": "Variant", + "desc": "The DOMElement node added or FALSE if any errors occur." + }, + "args": [ + { + "name": "node", + "type": "Object", + "desc": "The SimpleXMLElement node." + } + ] } ], "classes": [ @@ -4481,4 +4499,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/hphp/runtime/ext/ext_domdocument.cpp b/hphp/runtime/ext/ext_domdocument.cpp index 1615082e6..969a94000 100644 --- a/hphp/runtime/ext/ext_domdocument.cpp +++ b/hphp/runtime/ext/ext_domdocument.cpp @@ -20,6 +20,7 @@ #include "hphp/runtime/ext/ext_class.h" #include "hphp/runtime/base/runtime_error.h" #include "hphp/runtime/ext/ext_function.h" +#include "hphp/runtime/ext/ext_simplexml.h" #include "hphp/runtime/vm/translator/translator-inline.h" #include "hphp/system/lib/systemlib.h" @@ -5836,5 +5837,19 @@ Variant f_dom_xpath_register_php_functions(CVarRef obj, return pobj->t_registerphpfunctions(funcs); } +Variant f_dom_import_simplexml(CObjRef node) { + + c_SimpleXMLElement *elem = node.getTyped(); + xmlNodePtr nodep = elem->m_node; + + if (nodep && (nodep->type == XML_ELEMENT_NODE || + nodep->type == XML_ATTRIBUTE_NODE)) { + return create_node_object(nodep, SystemLib::AllocDOMDocumentObject()); + } else { + raise_warning("Invalid Nodetype to import"); + return uninit_null(); + } +} + /////////////////////////////////////////////////////////////////////////////// } diff --git a/hphp/runtime/ext/ext_domdocument.h b/hphp/runtime/ext/ext_domdocument.h index e264362c2..7a0b9462f 100644 --- a/hphp/runtime/ext/ext_domdocument.h +++ b/hphp/runtime/ext/ext_domdocument.h @@ -97,6 +97,7 @@ Variant f_dom_xpath_register_ns(CVarRef obj, CStrRef prefix, CStrRef uri); Variant f_dom_xpath_query(CVarRef obj, CStrRef expr, CObjRef context = null_object); Variant f_dom_xpath_evaluate(CVarRef obj, CStrRef expr, CObjRef context = null_object); Variant f_dom_xpath_register_php_functions(CVarRef obj, CVarRef funcs = uninit_null()); +Variant f_dom_import_simplexml(CObjRef node); /////////////////////////////////////////////////////////////////////////////// // class DOMNode diff --git a/hphp/system/class_map.cpp b/hphp/system/class_map.cpp index ee1cc7f44..385db0939 100644 --- a/hphp/system/class_map.cpp +++ b/hphp/system/class_map.cpp @@ -10161,6 +10161,12 @@ const char *g_class_map[] = { NULL, NULL, NULL, + (const char *)0x10006040, "dom_import_simplexml", "", (const char*)0, (const char*)0, + "/**\n * ( excerpt from\n * http://php.net/manual/en/function.dom-import-simplexml.php )\n *\n * This function takes the node node of class SimpleXML and makes it into\n * a DOMElement node. This new object can then be used as a native\n * DOMElement node.\n *\n * @node object The SimpleXMLElement node.\n *\n * @return mixed The DOMElement node added or FALSE if any errors\n * occur.\n */", + (const char *)0xffffffff /* KindOfUnknown: $t: Variant */, (const char *)0x2000, "node", "", (const char *)0x40 /* KindOfObject */, "", (const char *)0, "", (const char *)0, NULL, + NULL, + NULL, + NULL, (const char *)0x10016040, "hphp_splfileinfo___construct", "", (const char*)0, (const char*)0, "/**\n * ( HipHop specific )\n *\n *\n * @obj resource\n *\n * @file_name string\n *\n * @return resource\n *\n */", (const char *)0x40 /* KindOfObject */, (const char *)0x2000, "obj", "", (const char *)0x40 /* KindOfObject */, "", (const char *)0, "", (const char *)0, NULL, diff --git a/hphp/system/lib/systemlib.cpp b/hphp/system/lib/systemlib.cpp index 9a24aff58..5e9ab13b3 100644 --- a/hphp/system/lib/systemlib.cpp +++ b/hphp/system/lib/systemlib.cpp @@ -90,6 +90,11 @@ ObjectData* SystemLib::AllocInvalidOperationExceptionObject(CVarRef message) { CREATE_AND_CONSTRUCT(InvalidOperationException, CREATE_VECTOR1(message)); } +ObjectData* SystemLib::AllocDOMDocumentObject(CStrRef version, + CStrRef encoding) { + CREATE_AND_CONSTRUCT(DOMDocument, CREATE_VECTOR2(version, encoding)); +} + ObjectData* SystemLib::AllocDOMExceptionObject(CVarRef message, CVarRef code) { CREATE_AND_CONSTRUCT(DOMException, CREATE_VECTOR2(message, code)); } diff --git a/hphp/system/lib/systemlib.h b/hphp/system/lib/systemlib.h index a7c83b466..a1638b1f7 100644 --- a/hphp/system/lib/systemlib.h +++ b/hphp/system/lib/systemlib.h @@ -46,6 +46,7 @@ namespace Eval { x(DirectoryIterator) \ x(SplFileInfo) \ x(SplFileObject) \ + x(DOMDocument) \ x(DOMException) \ x(PDOException) \ x(SoapFault) \ @@ -90,6 +91,8 @@ class SystemLib { static ObjectData* AllocRuntimeExceptionObject(CVarRef message); static ObjectData* AllocOutOfBoundsExceptionObject(CVarRef message); static ObjectData* AllocInvalidOperationExceptionObject(CVarRef message); + static ObjectData* AllocDOMDocumentObject(CStrRef version = null_string, + CStrRef encoding = null_string); static ObjectData* AllocDOMExceptionObject(CVarRef message, CVarRef code); static ObjectData* AllocDirectoryObject(); diff --git a/hphp/test/slow/simple_xml/dom_import_simplexml.php b/hphp/test/slow/simple_xml/dom_import_simplexml.php new file mode 100644 index 000000000..4dd1a30d4 --- /dev/null +++ b/hphp/test/slow/simple_xml/dom_import_simplexml.php @@ -0,0 +1,7 @@ +c'); + $dom = dom_import_simplexml($s); + print $dom->ownerDocument->saveXML(); +} +main(); diff --git a/hphp/test/slow/simple_xml/dom_import_simplexml.php.expect b/hphp/test/slow/simple_xml/dom_import_simplexml.php.expect new file mode 100644 index 000000000..5b3a1344c --- /dev/null +++ b/hphp/test/slow/simple_xml/dom_import_simplexml.php.expect @@ -0,0 +1,2 @@ + +c