mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-29 20:59:46 +01:00
php: added unpack of class object converter
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "php_msgpack.h"
|
||||
#include "msgpack_pack.h"
|
||||
#include "msgpack_errors.h"
|
||||
|
||||
#include "msgpack/pack_define.h"
|
||||
#define msgpack_pack_user smart_str*
|
||||
@@ -18,7 +19,7 @@
|
||||
smart_str_appendl(user, (const void*)buf, len)
|
||||
#include "msgpack/pack_template.h"
|
||||
|
||||
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3)
|
||||
#if ZEND_MODULE_API_NO < 20090626
|
||||
# define Z_ISREF_P(pz) PZVAL_IS_REF(pz)
|
||||
#endif
|
||||
|
||||
@@ -123,15 +124,10 @@ inline static void msgpack_serialize_class(
|
||||
|
||||
if (Z_TYPE_PP(name) != IS_STRING)
|
||||
{
|
||||
if (MSGPACK_G(error_display))
|
||||
{
|
||||
zend_error(E_NOTICE,
|
||||
"[msgpack] (%s) "
|
||||
"__sleep should return an array only "
|
||||
"containing the names of "
|
||||
"instance-variables to serialize.",
|
||||
__FUNCTION__);
|
||||
}
|
||||
MSGPACK_NOTICE(
|
||||
"[msgpack] (%s) __sleep should return an array only "
|
||||
"containing the names of instance-variables to serialize",
|
||||
__FUNCTION__);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -201,14 +197,10 @@ inline static void msgpack_serialize_class(
|
||||
|
||||
pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
|
||||
|
||||
if (MSGPACK_G(error_display))
|
||||
{
|
||||
zend_error(E_NOTICE,
|
||||
"[msgpack] (%s) "
|
||||
"\"%s\" returned as member variable from "
|
||||
"__sleep() but does not exist",
|
||||
__FUNCTION__, Z_STRVAL_PP(name));
|
||||
}
|
||||
MSGPACK_NOTICE(
|
||||
"[msgpack] (%s) \"%s\" returned as member "
|
||||
"variable from __sleep() but does not exist",
|
||||
__FUNCTION__, Z_STRVAL_PP(name));
|
||||
|
||||
msgpack_serialize_string(
|
||||
buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
|
||||
@@ -291,18 +283,20 @@ inline static void msgpack_serialize_array(
|
||||
hash = 0;
|
||||
msgpack_pack_array(buf, n);
|
||||
}
|
||||
else if (Z_ISREF_P(val) && MSGPACK_G(php_only))
|
||||
{
|
||||
msgpack_pack_map(buf, n + 1);
|
||||
msgpack_pack_nil(buf);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE);
|
||||
}
|
||||
else if (ht->nNumOfElements == ht->nNextFreeElement)
|
||||
{
|
||||
hash = 0;
|
||||
msgpack_pack_array(buf, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Z_ISREF_P(val) && MSGPACK_G(php_only))
|
||||
{
|
||||
msgpack_pack_map(buf, n + 1);
|
||||
msgpack_pack_nil(buf);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE);
|
||||
}
|
||||
else
|
||||
{
|
||||
msgpack_pack_map(buf, n);
|
||||
}
|
||||
msgpack_pack_map(buf, n);
|
||||
}
|
||||
|
||||
if (n > 0)
|
||||
@@ -341,13 +335,9 @@ inline static void msgpack_serialize_array(
|
||||
break;
|
||||
default:
|
||||
msgpack_serialize_string(buf, "", sizeof(""));
|
||||
if (MSGPACK_G(error_display))
|
||||
{
|
||||
zend_error(E_WARNING,
|
||||
"[msgpack] (%s) "
|
||||
"key is not string nor array",
|
||||
__FUNCTION__);
|
||||
}
|
||||
MSGPACK_WARNING(
|
||||
"[msgpack] (%s) key is not string nor array",
|
||||
__FUNCTION__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -446,15 +436,10 @@ inline static void msgpack_serialize_object(
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MSGPACK_G(error_display))
|
||||
{
|
||||
zend_error(E_NOTICE,
|
||||
"[msgpack] (%s) "
|
||||
"__sleep should return an array only "
|
||||
"containing the names of instance-variables "
|
||||
"to serialize",
|
||||
__FUNCTION__);
|
||||
}
|
||||
MSGPACK_NOTICE(
|
||||
"[msgpack] (%s) __sleep should return an array only "
|
||||
"containing the names of instance-variables "
|
||||
"to serialize", __FUNCTION__);
|
||||
msgpack_pack_nil(buf);
|
||||
}
|
||||
zval_ptr_dtor(&retval_ptr);
|
||||
@@ -483,24 +468,39 @@ void msgpack_serialize_zval(
|
||||
msgpack_var_add(
|
||||
var_hash, val, (void *)&var_already TSRMLS_CC) == FAILURE)
|
||||
{
|
||||
if (Z_ISREF_P(val) && Z_TYPE_P(val) == IS_ARRAY)
|
||||
if (Z_ISREF_P(val))
|
||||
{
|
||||
msgpack_pack_map(buf, 2);
|
||||
if (Z_TYPE_P(val) == IS_ARRAY)
|
||||
{
|
||||
msgpack_pack_map(buf, 2);
|
||||
|
||||
msgpack_pack_nil(buf);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_RECURSIVE);
|
||||
msgpack_pack_nil(buf);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_RECURSIVE);
|
||||
|
||||
msgpack_pack_long(buf, 0);
|
||||
msgpack_pack_long(buf, *var_already);
|
||||
msgpack_pack_long(buf, 0);
|
||||
msgpack_pack_long(buf, *var_already);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
else if (Z_TYPE_P(val) == IS_OBJECT)
|
||||
{
|
||||
msgpack_pack_map(buf, 2);
|
||||
|
||||
msgpack_pack_nil(buf);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE);
|
||||
|
||||
msgpack_pack_long(buf, 0);
|
||||
msgpack_pack_long(buf, *var_already);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (Z_TYPE_P(val) == IS_OBJECT)
|
||||
{
|
||||
msgpack_pack_map(buf, 2);
|
||||
|
||||
msgpack_pack_nil(buf);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_RECURSIVE);
|
||||
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT);
|
||||
|
||||
msgpack_pack_long(buf, 0);
|
||||
msgpack_pack_long(buf, *var_already);
|
||||
@@ -554,12 +554,9 @@ void msgpack_serialize_zval(
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (MSGPACK_G(error_display))
|
||||
{
|
||||
zend_error(E_WARNING,
|
||||
"[msgpack] (%s) type is unsupported, encoded as null",
|
||||
__FUNCTION__);
|
||||
}
|
||||
MSGPACK_WARNING(
|
||||
"[msgpack] (%s) type is unsupported, encoded as null",
|
||||
__FUNCTION__);
|
||||
msgpack_pack_nil(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user