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?
Esse commit está contido em:
Paul Tarjan
2013-05-21 15:27:29 -07:00
commit de Sara Golemon
commit d4f57cbe3e
8 arquivos alterados com 58 adições e 1 exclusões
+19 -1
Ver Arquivo
@@ -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 @@
]
}
]
}
}
+15
Ver Arquivo
@@ -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<c_SimpleXMLElement>();
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();
}
}
///////////////////////////////////////////////////////////////////////////////
}
+1
Ver Arquivo
@@ -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
+6
Ver Arquivo
@@ -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,
+5
Ver Arquivo
@@ -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));
}
+3
Ver Arquivo
@@ -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();
@@ -0,0 +1,7 @@
<?php
function main() {
$s = simplexml_load_string('<a><b>c</b></a>');
$dom = dom_import_simplexml($s);
print $dom->ownerDocument->saveXML();
}
main();
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<a><b>c</b></a>