mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Refactor simpleXML (compilable, but incompleted)
This commit is contained in:
parent
b178992cd1
commit
a975c7e0fe
5 changed files with 219 additions and 261 deletions
|
@ -75,10 +75,10 @@ typedef struct _php_libxml_node_ptr {
|
||||||
} php_libxml_node_ptr;
|
} php_libxml_node_ptr;
|
||||||
|
|
||||||
typedef struct _php_libxml_node_object {
|
typedef struct _php_libxml_node_object {
|
||||||
zend_object std;
|
|
||||||
php_libxml_node_ptr *node;
|
php_libxml_node_ptr *node;
|
||||||
php_libxml_ref_obj *document;
|
php_libxml_ref_obj *document;
|
||||||
HashTable *properties;
|
HashTable *properties;
|
||||||
|
zend_object std;
|
||||||
} php_libxml_node_object;
|
} php_libxml_node_object;
|
||||||
|
|
||||||
typedef void * (*php_libxml_export_node) (zval *object TSRMLS_DC);
|
typedef void * (*php_libxml_export_node) (zval *object TSRMLS_DC);
|
||||||
|
|
|
@ -55,7 +55,6 @@ typedef enum {
|
||||||
} SXE_ITER;
|
} SXE_ITER;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
zend_object zo;
|
|
||||||
php_libxml_node_ptr *node;
|
php_libxml_node_ptr *node;
|
||||||
php_libxml_ref_obj *document;
|
php_libxml_ref_obj *document;
|
||||||
HashTable *properties;
|
HashTable *properties;
|
||||||
|
@ -65,10 +64,11 @@ typedef struct {
|
||||||
xmlChar *nsprefix;
|
xmlChar *nsprefix;
|
||||||
int isprefix;
|
int isprefix;
|
||||||
SXE_ITER type;
|
SXE_ITER type;
|
||||||
zval *data;
|
zval data;
|
||||||
} iter;
|
} iter;
|
||||||
zval *tmp;
|
zval tmp;
|
||||||
zend_function *fptr_count;
|
zend_function *fptr_count;
|
||||||
|
zend_object zo;
|
||||||
} php_sxe_object;
|
} php_sxe_object;
|
||||||
|
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
|
|
|
@ -39,16 +39,15 @@
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_SXE_API zend_object_value sxe_object_new(zend_class_entry *ce TSRMLS_DC);
|
PHP_SXE_API zend_object *sxe_object_new(zend_class_entry *ce TSRMLS_DC);
|
||||||
/* {{{ php_sxe_fetch_object()
|
|
||||||
*/
|
static inline php_sxe_object *php_sxe_fetch_object(zend_object *obj) /* {{{ */ {
|
||||||
static inline php_sxe_object *
|
return (php_sxe_object *)((char*)(obj) - XtOffsetOf(php_sxe_object, zo));
|
||||||
php_sxe_fetch_object(zval *object TSRMLS_DC)
|
|
||||||
{
|
|
||||||
return (php_sxe_object *) zend_object_store_get_object(object TSRMLS_CC);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
#define Z_SXEOBJ_P(zv) php_sxe_fetch_object(Z_OBJ_P((zv)))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
zend_object_iterator intern;
|
zend_object_iterator intern;
|
||||||
php_sxe_object *sxe;
|
php_sxe_object *sxe;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -46,7 +46,7 @@ PHP_METHOD(ce_SimpleXMLIterator, rewind)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
iter.sxe = Z_SXEOBJ_P(getThis());
|
||||||
ce_SimpleXMLElement->iterator_funcs.funcs->rewind((zend_object_iterator*)&iter TSRMLS_CC);
|
ce_SimpleXMLElement->iterator_funcs.funcs->rewind((zend_object_iterator*)&iter TSRMLS_CC);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -55,13 +55,13 @@ PHP_METHOD(ce_SimpleXMLIterator, rewind)
|
||||||
Check whether iteration is valid */
|
Check whether iteration is valid */
|
||||||
PHP_METHOD(ce_SimpleXMLIterator, valid)
|
PHP_METHOD(ce_SimpleXMLIterator, valid)
|
||||||
{
|
{
|
||||||
php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
|
||||||
|
|
||||||
if (zend_parse_parameters_none() == FAILURE) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_BOOL(sxe->iter.data);
|
RETURN_BOOL(!ZVAL_IS_UNDEF(&sxe->iter.data));
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -69,17 +69,17 @@ PHP_METHOD(ce_SimpleXMLIterator, valid)
|
||||||
Get current element */
|
Get current element */
|
||||||
PHP_METHOD(ce_SimpleXMLIterator, current)
|
PHP_METHOD(ce_SimpleXMLIterator, current)
|
||||||
{
|
{
|
||||||
php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
|
||||||
|
|
||||||
if (zend_parse_parameters_none() == FAILURE) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sxe->iter.data) {
|
if (ZVAL_IS_UNDEF(&sxe->iter.data)) {
|
||||||
return; /* return NULL */
|
return; /* return NULL */
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_ZVAL(sxe->iter.data, 1, 0);
|
RETURN_ZVAL(&sxe->iter.data, 1, 0);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -89,20 +89,20 @@ PHP_METHOD(ce_SimpleXMLIterator, key)
|
||||||
{
|
{
|
||||||
xmlNodePtr curnode;
|
xmlNodePtr curnode;
|
||||||
php_sxe_object *intern;
|
php_sxe_object *intern;
|
||||||
php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
|
||||||
|
|
||||||
if (zend_parse_parameters_none() == FAILURE) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sxe->iter.data) {
|
if (ZVAL_IS_UNDEF(&sxe->iter.data)) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
|
intern = Z_SXEOBJ_P(&sxe->iter.data);
|
||||||
if (intern != NULL && intern->node != NULL) {
|
if (intern != NULL && intern->node != NULL) {
|
||||||
curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
|
curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
|
||||||
RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name), 1);
|
RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -119,7 +119,7 @@ PHP_METHOD(ce_SimpleXMLIterator, next)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
iter.sxe = Z_SXEOBJ_P(getThis());
|
||||||
ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter TSRMLS_CC);
|
ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter TSRMLS_CC);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -128,7 +128,7 @@ PHP_METHOD(ce_SimpleXMLIterator, next)
|
||||||
Check whether element has children (elements) */
|
Check whether element has children (elements) */
|
||||||
PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
|
PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
|
||||||
{
|
{
|
||||||
php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
|
||||||
php_sxe_object *child;
|
php_sxe_object *child;
|
||||||
xmlNodePtr node;
|
xmlNodePtr node;
|
||||||
|
|
||||||
|
@ -136,10 +136,10 @@ PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) {
|
if (ZVAL_IS_UNDEF(&sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
child = php_sxe_fetch_object(sxe->iter.data TSRMLS_CC);
|
child = Z_SXEOBJ_P(&sxe->iter.data);
|
||||||
|
|
||||||
GET_NODE(child, node);
|
GET_NODE(child, node);
|
||||||
if (node) {
|
if (node) {
|
||||||
|
@ -156,16 +156,16 @@ PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
|
||||||
Get child element iterator */
|
Get child element iterator */
|
||||||
PHP_METHOD(ce_SimpleXMLIterator, getChildren)
|
PHP_METHOD(ce_SimpleXMLIterator, getChildren)
|
||||||
{
|
{
|
||||||
php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
|
||||||
|
|
||||||
if (zend_parse_parameters_none() == FAILURE) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) {
|
if (ZVAL_IS_UNDEF(&sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
|
||||||
return; /* return NULL */
|
return; /* return NULL */
|
||||||
}
|
}
|
||||||
RETURN_ZVAL(sxe->iter.data, 1, 0);
|
RETURN_ZVAL(&sxe->iter.data, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* {{{ arginfo */
|
/* {{{ arginfo */
|
||||||
|
@ -187,18 +187,18 @@ static const zend_function_entry funcs_SimpleXMLIterator[] = {
|
||||||
|
|
||||||
PHP_MINIT_FUNCTION(sxe) /* {{{ */
|
PHP_MINIT_FUNCTION(sxe) /* {{{ */
|
||||||
{
|
{
|
||||||
zend_class_entry **pce;
|
zend_class_entry *pce;
|
||||||
zend_class_entry sxi;
|
zend_class_entry sxi;
|
||||||
|
|
||||||
if (zend_hash_find(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement"), (void **) &pce) == FAILURE) {
|
if ((pce = zend_hash_str_find_ptr(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement") - 1)) == NULL) {
|
||||||
ce_SimpleXMLElement = NULL;
|
ce_SimpleXMLElement = NULL;
|
||||||
ce_SimpleXMLIterator = NULL;
|
ce_SimpleXMLIterator = NULL;
|
||||||
return SUCCESS; /* SimpleXML must be initialized before */
|
return SUCCESS; /* SimpleXML must be initialized before */
|
||||||
}
|
}
|
||||||
|
|
||||||
ce_SimpleXMLElement = *pce;
|
ce_SimpleXMLElement = pce;
|
||||||
|
|
||||||
INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", strlen("SimpleXMLIterator"), funcs_SimpleXMLIterator);
|
INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", sizeof("SimpleXMLIterator") - 1, funcs_SimpleXMLIterator);
|
||||||
ce_SimpleXMLIterator = zend_register_internal_class_ex(&sxi, ce_SimpleXMLElement TSRMLS_CC);
|
ce_SimpleXMLIterator = zend_register_internal_class_ex(&sxi, ce_SimpleXMLElement TSRMLS_CC);
|
||||||
ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;
|
ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue