From: Michael Wallner Date: Mon, 30 Jul 2012 18:32:30 +0000 (+0000) Subject: implement Serializable X-Git-Tag: RELEASE_2_1_0_RC3~10^2^2~115 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3d6119e310337b4453b30312ea65613208493cd3;p=m6w6%2Fext-http implement Serializable --- diff --git a/php_http_message_body.c b/php_http_message_body.c index 9d0f226..40a1688 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -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;