#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "php_simplexml.h"
+#include "zend_default_classes.h"
#if HAVE_SPL && !defined(COMPILE_DL_SPL)
#include "ext/spl/spl_iterators.h"
goto next_iter; \
}
-static php_sxe_object *php_sxe_object_new(TSRMLS_D);
+static php_sxe_object *php_sxe_object_new(zend_class_entry *ce TSRMLS_DC);
static zend_object_value php_sxe_register_object(php_sxe_object * TSRMLS_DC);
/* {{{ php_sxe_fetch_object()
{
php_sxe_object *subnode;
- subnode = php_sxe_object_new(TSRMLS_C);
+ subnode = php_sxe_object_new(sxe_class_entry TSRMLS_CC);
subnode->document = sxe->document;
subnode->document->refcount++;
subnode->nsmapptr = sxe->nsmapptr;
xmlFree(contents);
}
} else {
- subnode = php_sxe_object_new(TSRMLS_C);
+ subnode = php_sxe_object_new(sxe_class_entry TSRMLS_CC);
subnode->document = sxe_ref->document;
subnode->document->refcount++;
subnode->nsmapptr = sxe_ref->nsmapptr;
}
/* }}} */
-/* {{{ sxe_constructor_get()
- */
-static union _zend_function *
-sxe_constructor_get(zval *object TSRMLS_DC)
-{
- return NULL;
-}
-/* }}} */
-
-/* {{{ sxe_method_get()
- */
-static union _zend_function *
-sxe_method_get(zval *object, char *name, int len TSRMLS_DC)
-{
- zend_internal_function *f;
-
- f = emalloc(sizeof(zend_internal_function));
- f->type = ZEND_OVERLOADED_FUNCTION_TEMPORARY;
- f->arg_info = NULL;
- f->num_args = 0;
- f->scope = sxe_class_entry;
- f->fn_flags = 0;
- f->function_name = estrndup(name, len);
-
- return (union _zend_function *) f;
-}
-/* }}} */
-
/* {{{ simplexml_ce_xpath_register_ns()
*/
static void
}
/* }}} */
-/* {{{ sxe_object_set()
- */
-static void
-sxe_object_set(zval **property, zval *value TSRMLS_DC)
-{
- /* XXX: TODO
- * This call is not yet implemented in the engine
- * so leave it blank for now.
- */
-}
-/* }}} */
-
-/* {{{ sxe_object_get()
- */
-static zval *
-sxe_object_get(zval *property TSRMLS_DC)
-{
- /* XXX: TODO
- * This call is not yet implemented in the engine
- * so leave it blank for now.
- */
- return NULL;
-}
-/* }}} */
-
static zend_object_handlers sxe_object_handlers = {
ZEND_OBJECTS_STORE_HANDLERS,
sxe_property_read,
sxe_dimension_read,
sxe_dimension_write,
NULL,
- sxe_object_get,
- sxe_object_set,
+ NULL,
+ NULL,
sxe_property_exists,
sxe_property_delete,
sxe_dimension_exists,
sxe_dimension_delete,
sxe_properties_get,
- sxe_method_get,
NULL, /* zend_get_std_object_handlers()->get_method,*/
- sxe_constructor_get,
+ NULL, /* zend_get_std_object_handlers()->call_method,*/
+ NULL, /* zend_get_std_object_handlers()->get_constructor, */
NULL, /* zend_get_std_object_handlers()->get_class_entry,*/
NULL, /* zend_get_std_object_handlers()->get_class_name,*/
sxe_objects_compare,
xmlNodePtr nodep = NULL;
xmlDocPtr docp = NULL;
- clone = php_sxe_object_new(TSRMLS_C);
+ clone = php_sxe_object_new(sxe_class_entry TSRMLS_CC);
clone->document = sxe->document;
if (clone->document) {
clone->document->refcount++;
php_libxml_node_decrement_resource((php_libxml_node_object *)sxe TSRMLS_CC);
- if (--sxe->nsmapptr->refcount == 0) {
+ if (sxe->nsmapptr && --sxe->nsmapptr->refcount == 0) {
xmlHashFree(sxe->nsmapptr->nsmap, _free_ns_entry);
efree(sxe->nsmapptr);
}
/* {{{ php_sxe_object_new()
*/
-static php_sxe_object* php_sxe_object_new(TSRMLS_D)
+static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC)
{
php_sxe_object *intern;
intern = ecalloc(1, sizeof(php_sxe_object));
- intern->zo.ce = sxe_class_entry;
+ intern->zo.ce = ce;
ALLOC_HASHTABLE(intern->zo.properties);
zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
{
php_sxe_object *intern;
- intern = php_sxe_object_new(TSRMLS_C);
+ intern = php_sxe_object_new(ce TSRMLS_CC);
return php_sxe_register_object(intern TSRMLS_CC);
}
/* }}} */
RETURN_FALSE;
}
- sxe = php_sxe_object_new(TSRMLS_C);
+ sxe = php_sxe_object_new(sxe_class_entry TSRMLS_CC);
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
sxe->nsmapptr->nsmap = xmlHashCreate(10);
RETURN_FALSE;
}
- sxe = php_sxe_object_new(TSRMLS_C);
+ sxe = php_sxe_object_new(sxe_class_entry TSRMLS_CC);
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
sxe->nsmapptr->nsmap = xmlHashCreate(10);
}
/* }}} */
+SXE_METHOD(__construct)
+{
+ php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+ char *data;
+ int data_len;
+ xmlDocPtr docp;
+
+ php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) {
+ php_std_error_handling();
+ return;
+ }
+
+ php_std_error_handling();
+ docp = xmlParseMemory(data, data_len);
+ if (!docp) {
+ (php_libxml_node_object *)sxe->document = NULL;
+ zend_throw_exception(zend_exception_get_default(), "String could not be parsed as XML", 0 TSRMLS_CC);
+ return;
+ }
+
+ php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
+ sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
+ sxe->nsmapptr->nsmap = xmlHashCreate(10);
+ sxe->nsmapptr->refcount = 1;
+ php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC);
+}
+
typedef struct {
zend_object_iterator intern;
php_sxe_object *sxe;
}
if (nodep && nodep->type == XML_ELEMENT_NODE) {
- sxe = php_sxe_object_new(TSRMLS_C);
+ sxe = php_sxe_object_new(sxe_class_entry TSRMLS_CC);
sxe->document = object->document;
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, nodep->doc TSRMLS_CC);
sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
/* the method table */
/* each method can have its own parameters and visibility */
static zend_function_entry sxe_functions[] = {
+ SXE_ME(__construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) /* must be called */
SXE_ME(register_ns, NULL, ZEND_ACC_PUBLIC)
SXE_ME(to_xml_file, NULL, ZEND_ACC_PUBLIC)
SXE_ME(to_xml_string, NULL, ZEND_ACC_PUBLIC)
sxe_class_entry = zend_register_internal_class(&sxe TSRMLS_CC);
sxe_class_entry->get_iterator = php_sxe_get_iterator;
sxe_object_handlers.get_method = zend_get_std_object_handlers()->get_method;
+ sxe_object_handlers.get_constructor = zend_get_std_object_handlers()->get_constructor;
sxe_object_handlers.get_class_entry = zend_get_std_object_handlers()->get_class_entry;
sxe_object_handlers.get_class_name = zend_get_std_object_handlers()->get_class_name;