From: Michael Wallner Date: Wed, 22 Dec 2021 16:32:48 +0000 (+0100) Subject: discard a few previous ideas X-Git-Tag: v0.1.0~56 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e1d8621fc8f0e88bd98174e11e2384a09d838d7f;p=awesomized%2Fext-ion discard a few previous ideas --- diff --git a/ion.c b/ion.c index f6fb4d3..45f34b8 100644 --- a/ion.c +++ b/ion.c @@ -1682,7 +1682,7 @@ static ZEND_METHOD(ion_Serializer_PHP, __construct) php_ion_serializer_php_ctor(obj); } -static ZEND_METHOD(ion_Serializer_PHP, __invoke) +static ZEND_METHOD(ion_Serializer_PHP, serialize) { zend_object *obj = Z_OBJ_P(ZEND_THIS); @@ -1691,12 +1691,7 @@ static ZEND_METHOD(ion_Serializer_PHP, __invoke) Z_PARAM_ZVAL(data) ZEND_PARSE_PARAMETERS_END(); - if (obj->ce == ce_Serializer_PHP) { - // default, fast path - php_ion_serialize(&php_ion_obj(serializer_php, obj)->serializer, data, return_value); - } else { - zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "serialize", return_value, data); - } + php_ion_serialize(&php_ion_obj(serializer_php, obj)->serializer, data, return_value); } static ZEND_FUNCTION(ion_serialize) { @@ -1713,21 +1708,9 @@ static ZEND_FUNCTION(ion_serialize) php_ion_serializer *ser = zo_ser ? &php_ion_obj(serializer_php, zo_ser)->serializer : NULL; php_ion_serialize(ser, data, return_value); } else { - zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data); + zend_call_method_with_1_params(zo_ser, NULL, NULL, "serialize", return_value, data); } } -static ZEND_METHOD(ion_Serializer_PHP, serialize) -{ - //zend_object *obj = Z_OBJ_P(ZEND_THIS); - - zval *data; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(data) - ZEND_PARSE_PARAMETERS_END(); - - // TODO - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented"); -} static ZEND_METHOD(ion_Unserializer_PHP, __construct) { @@ -1746,7 +1729,7 @@ static ZEND_METHOD(ion_Unserializer_PHP, __construct) php_ion_unserializer_php_ctor(obj); } -static ZEND_METHOD(ion_Unserializer_PHP, __invoke) +static ZEND_METHOD(ion_Unserializer_PHP, unserialize) { zend_object *obj = Z_OBJ_P(ZEND_THIS); @@ -1755,11 +1738,7 @@ static ZEND_METHOD(ion_Unserializer_PHP, __invoke) Z_PARAM_ZVAL(data) ZEND_PARSE_PARAMETERS_END(); - if (obj->ce == ce_Unserializer_PHP) { - php_ion_unserialize(&php_ion_obj(unserializer_php, obj)->unserializer, data, return_value); - } else { - zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "unserialize", return_value, data); - } + php_ion_unserialize(&php_ion_obj(unserializer_php, obj)->unserializer, data, return_value); } static ZEND_FUNCTION(ion_unserialize) { @@ -1779,18 +1758,6 @@ static ZEND_FUNCTION(ion_unserialize) zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data); } } -static ZEND_METHOD(ion_Unserializer_PHP, unserialize) -{ - //zend_object *obj = Z_OBJ_P(ZEND_THIS); - - zval *data; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(data) - ZEND_PARSE_PARAMETERS_END(); - - // TODO - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented"); -} PHP_RINIT_FUNCTION(ion) { diff --git a/ion.stub.php b/ion.stub.php index f317abc..8a34269 100644 --- a/ion.stub.php +++ b/ion.stub.php @@ -530,15 +530,12 @@ class Writer extends \ion\Writer\Writer implements \ion\Writer\Stream { namespace ion; interface Serializer { - public function __invoke(mixed $data) : string; - // protected function serialize(mixed $data) : string; + public function serialize(mixed $data) : string; } namespace ion; interface Unserializer { /** @param string|resource $data */ - public function __invoke($data) : mixed; - // /** @param string|resource $data */ - // protected function unserialize($data) : mixed; + public function unserialize($data) : mixed; } namespace ion\Serializer; @@ -549,8 +546,7 @@ class PHP implements \ion\Serializer { public readonly bool $callMagicSerialize = true, public readonly ?string $callCustomSerialize = null, ) {} - public function __invoke(mixed $data) : string {} - protected function serialize(mixed $data) : string {} + public function serialize(mixed $data) : string {} } namespace ion\Unserializer; @@ -562,9 +558,7 @@ class PHP implements \ion\Unserializer { public readonly ?string $callCustomUnserialize = null, ){} /** @param string|resource $data */ - public function __invoke($data) : mixed {} - /** @param string|resource $data */ - protected function unserialize($data) : mixed {} + public function unserialize($data) : mixed {} } namespace ion; diff --git a/ion_arginfo.h b/ion_arginfo.h index 2f02cec..c600e68 100644 --- a/ion_arginfo.h +++ b/ion_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7322502dd0c48787538abe7e2fa1894b20a736ba */ + * Stub hash: 6aa30c4f415607e9d724405a1b4c0fb10e4027f3 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_ion_Symbol_Table_PHP, 0, 0, ion\\Symbol\\Table, 0) ZEND_END_ARG_INFO() @@ -512,11 +512,11 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Writer_Stream_Writer_getStream arginfo_class_ion_Symbol_Table_Local___construct -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Serializer___invoke, 0, 1, IS_STRING, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Serializer_serialize, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, data, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Unserializer___invoke, 0, 1, IS_MIXED, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Unserializer_unserialize, 0, 1, IS_MIXED, 0) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() @@ -527,9 +527,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Serializer_PHP___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callCustomSerialize, IS_STRING, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_ion_Serializer_PHP___invoke arginfo_class_ion_Serializer___invoke - -#define arginfo_class_ion_Serializer_PHP_serialize arginfo_class_ion_Serializer___invoke +#define arginfo_class_ion_Serializer_PHP_serialize arginfo_class_ion_Serializer_serialize ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Unserializer_PHP___construct, 0, 0, 0) ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, readerOptions, ion\\Reader\\Options, 1, "null") @@ -538,9 +536,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Unserializer_PHP___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callCustomUnserialize, IS_STRING, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_ion_Unserializer_PHP___invoke arginfo_class_ion_Unserializer___invoke - -#define arginfo_class_ion_Unserializer_PHP_unserialize arginfo_class_ion_Unserializer___invoke +#define arginfo_class_ion_Unserializer_PHP_unserialize arginfo_class_ion_Unserializer_unserialize static ZEND_FUNCTION(ion_Symbol_Table_PHP); @@ -644,10 +640,8 @@ static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer); static ZEND_METHOD(ion_Writer_Stream_Writer, __construct); static ZEND_METHOD(ion_Writer_Stream_Writer, getStream); static ZEND_METHOD(ion_Serializer_PHP, __construct); -static ZEND_METHOD(ion_Serializer_PHP, __invoke); static ZEND_METHOD(ion_Serializer_PHP, serialize); static ZEND_METHOD(ion_Unserializer_PHP, __construct); -static ZEND_METHOD(ion_Unserializer_PHP, __invoke); static ZEND_METHOD(ion_Unserializer_PHP, unserialize); @@ -987,29 +981,27 @@ static const zend_function_entry class_ion_Writer_Stream_Writer_methods[] = { static const zend_function_entry class_ion_Serializer_methods[] = { - ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Serializer, __invoke, arginfo_class_ion_Serializer___invoke, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) + ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Serializer, serialize, arginfo_class_ion_Serializer_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_FE_END }; static const zend_function_entry class_ion_Unserializer_methods[] = { - ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Unserializer, __invoke, arginfo_class_ion_Unserializer___invoke, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) + ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Unserializer, unserialize, arginfo_class_ion_Unserializer_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_FE_END }; static const zend_function_entry class_ion_Serializer_PHP_methods[] = { ZEND_ME(ion_Serializer_PHP, __construct, arginfo_class_ion_Serializer_PHP___construct, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Serializer_PHP, __invoke, arginfo_class_ion_Serializer_PHP___invoke, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Serializer_PHP, serialize, arginfo_class_ion_Serializer_PHP_serialize, ZEND_ACC_PROTECTED) + ZEND_ME(ion_Serializer_PHP, serialize, arginfo_class_ion_Serializer_PHP_serialize, ZEND_ACC_PUBLIC) ZEND_FE_END }; static const zend_function_entry class_ion_Unserializer_PHP_methods[] = { ZEND_ME(ion_Unserializer_PHP, __construct, arginfo_class_ion_Unserializer_PHP___construct, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Unserializer_PHP, __invoke, arginfo_class_ion_Unserializer_PHP___invoke, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Unserializer_PHP, unserialize, arginfo_class_ion_Unserializer_PHP_unserialize, ZEND_ACC_PROTECTED) + ZEND_ME(ion_Unserializer_PHP, unserialize, arginfo_class_ion_Unserializer_PHP_unserialize, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/tests/Symbol/Table/Local.phpt b/tests/Symbol/Table/Local.phpt index 5dc7778..19a368e 100644 --- a/tests/Symbol/Table/Local.phpt +++ b/tests/Symbol/Table/Local.phpt @@ -26,7 +26,7 @@ foreach (str_split($buf, 8) as $line) { echo "\n"; $u = new ion\Unserializer\PHP(multiSequence: true); -var_dump($u($buf)); +var_dump($u->unserialize($buf)); ?> DONE diff --git a/tests/Symbol/Table/Shared.phpt b/tests/Symbol/Table/Shared.phpt index 25df25c..8740f01 100644 --- a/tests/Symbol/Table/Shared.phpt +++ b/tests/Symbol/Table/Shared.phpt @@ -28,13 +28,13 @@ foreach (str_split($buf, 8) as $line) { echo "\n"; $u = new ion\Unserializer\PHP(multiSequence: true); -var_dump($u($buf)); +var_dump($u->unserialize($buf)); $u = new ion\Unserializer\PHP(multiSequence: true, readerOptions: new ion\Reader\Options( catalog: $c, onContextChange: fn(ion\Reader $r) => print("on_context_change\n"))); -var_dump($u($buf)); +var_dump($u->unserialize($buf)); ?> DONE