discard a few previous ideas
authorMichael Wallner <mike@php.net>
Wed, 22 Dec 2021 16:32:48 +0000 (17:32 +0100)
committerMichael Wallner <mike@php.net>
Wed, 22 Dec 2021 16:32:48 +0000 (17:32 +0100)
ion.c
ion.stub.php
ion_arginfo.h
tests/Symbol/Table/Local.phpt
tests/Symbol/Table/Shared.phpt

diff --git a/ion.c b/ion.c
index f6fb4d367e04abd4f88b132a98556a747aba90ea..45f34b86d425ae776a4e47b1ef605171dd338384 100644 (file)
--- 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)
 {
index f317abc2a95618d079cccc40172a0662fe3f3561..8a3426917326dff79db3ae6814ce92125a190522 100644 (file)
@@ -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;
index 2f02cec872e48a3967ee035fd7a320f17aff3930..c600e68b2dde48f57a2675d4e6d130d613711dc7 100644 (file)
@@ -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
 };
 
index 5dc7778d22a102a1ef0cf4a4483034a63ee26965..19a368e0b3eaf28dd3e883e9c35b9c7de7ff9dac 100644 (file)
@@ -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
index 25df25cd192e5e1b841a89cb4a46bffbd0054f77..8740f0177eec7875a7917dbbb4834b026f252eb6 100644 (file)
@@ -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