implement Serializable
authorMichael Wallner <mike@php.net>
Mon, 30 Jul 2012 18:32:30 +0000 (18:32 +0000)
committerMichael Wallner <mike@php.net>
Mon, 30 Jul 2012 18:32:30 +0000 (18:32 +0000)
php_http_message_body.c

index 9d0f2263e856f7ca1d4dce2d162d223484cbe410..40a168876873d03cd312715b0d8c93e7a4b9755c 100644 (file)
@@ -537,6 +537,9 @@ PHP_HTTP_BEGIN_ARGS(__construct, 0)
 PHP_HTTP_END_ARGS;
 
 PHP_HTTP_EMPTY_ARGS(__toString);
+PHP_HTTP_BEGIN_ARGS(unserialize, 1)
+       PHP_HTTP_ARG_VAL(serialized, 0)
+PHP_HTTP_END_ARGS;
 
 PHP_HTTP_BEGIN_ARGS(toStream, 1)
        PHP_HTTP_ARG_VAL(stream, 0)
@@ -578,6 +581,8 @@ static zend_function_entry php_http_message_body_method_entry[] = {
        PHP_HTTP_MESSAGE_BODY_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_HTTP_MESSAGE_BODY_ME(__toString, ZEND_ACC_PUBLIC)
        PHP_MALIAS(HttpMessageBody, toString, __toString, args_for_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
+       PHP_MALIAS(HttpMessageBody, serialize, __toString, args_for_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
+       PHP_HTTP_MESSAGE_BODY_ME(unserialize, ZEND_ACC_PUBLIC)
        PHP_HTTP_MESSAGE_BODY_ME(toStream, ZEND_ACC_PUBLIC)
        PHP_HTTP_MESSAGE_BODY_ME(toCallback, ZEND_ACC_PUBLIC)
        PHP_HTTP_MESSAGE_BODY_ME(getResource, ZEND_ACC_PUBLIC)
@@ -596,7 +601,7 @@ PHP_MINIT_FUNCTION(http_message_body)
        php_http_message_body_class_entry->create_object = php_http_message_body_object_new;
        memcpy(&php_http_message_body_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_message_body_object_handlers.clone_obj = php_http_message_body_object_clone;
-
+       zend_class_implements(php_http_message_body_class_entry TSRMLS_CC, 1, zend_ce_serializable);
        return SUCCESS;
 }
 
@@ -694,6 +699,19 @@ PHP_METHOD(HttpMessageBody, __toString)
        RETURN_EMPTY_STRING();
 }
 
+PHP_METHOD(HttpMessageBody, unserialize)
+{
+       char *us_str;
+       int us_len;
+
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &us_str, &us_len)) {
+               php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_stream *s = php_stream_memory_open(0, us_str, us_len);
+
+               obj->body = php_http_message_body_init(NULL, s TSRMLS_CC);
+       }
+}
+
 PHP_METHOD(HttpMessageBody, toStream)
 {
        zval *zstream;