]> granicus.if.org Git - php/commitdiff
Custom object serializer infrastructure
authorStanislav Malyshev <stas@php.net>
Wed, 23 Feb 2005 11:15:51 +0000 (11:15 +0000)
committerStanislav Malyshev <stas@php.net>
Wed, 23 Feb 2005 11:15:51 +0000 (11:15 +0000)
# The detailed announce on the list will follow

Zend/zend.h
Zend/zend_compile.c

index f8a059ad8501c267b302807d2e8d4b7653f59f28..0583c09cb5126a2153e2b508aec8c737fae98ae3 100644 (file)
@@ -303,6 +303,12 @@ union _zend_function;
 
 #include "zend_iterators.h"
 
+struct _zend_serialize_data;
+struct _zend_unserialize_data;
+
+typedef struct _zend_serialize_data zend_serialize_data;
+typedef struct _zend_unserialize_data zend_unserialize_data;
+
 struct _zend_class_entry {
        char type;
        char *name;
@@ -333,6 +339,10 @@ struct _zend_class_entry {
        zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object TSRMLS_DC);
        int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */
 
+       /* serializer callbacks */
+       int (*serialize)(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC);
+       int (*unserialize)(zval **object, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC);
+
        zend_class_entry **interfaces;
        zend_uint num_interfaces;
 
index 32f2a3c26a02f24de342421dfa949d7aa22ffbc3..bf002ef9470e0b6fde12e745eabf2ccd6f94f7fc 100644 (file)
@@ -1707,7 +1707,7 @@ static void do_inherit_parent_constructor(zend_class_entry *ce)
 
        /* You cannot change create_object */
        ce->create_object = ce->parent->create_object;
-       
+
        /* Inherit special functions if needed */
        if (!ce->get_iterator) {
                ce->get_iterator = ce->parent->get_iterator;
@@ -1727,12 +1727,19 @@ static void do_inherit_parent_constructor(zend_class_entry *ce)
        if (!ce->clone) {
                ce->clone = ce->parent->clone;
        }
+       if(!ce->serialize) {
+               ce->serialize = ce->parent->serialize;
+       }
+       if(!ce->unserialize) {
+               ce->unserialize = ce->parent->unserialize;
+       }
        if (!ce->destructor) {
                ce->destructor   = ce->parent->destructor;
        }
        if (ce->constructor) {
                return;
        }
+       
        if (zend_hash_find(&ce->parent->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), (void **)&function)==SUCCESS) {
                /* inherit parent's constructor */
                zend_hash_update(&ce->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), function, sizeof(zend_function), NULL);
@@ -3839,6 +3846,8 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify
                ce->num_interfaces = 0;
                ce->interfaces = NULL;
                ce->module = NULL;
+               ce->serialize = NULL;
+               ce->unserialize = NULL;
        }
 }