From a9307301a2d398d045be9bc5c6adabfce7d14ad3 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 3 Jan 2022 23:06:24 +0300 Subject: [PATCH] feat(serializers): remove phpcode serializer for now --- src/flextype/core/Serializers/PhpCode.php | 113 ------------------ src/flextype/core/Serializers/Serializers.php | 8 -- src/flextype/settings.yaml | 5 - .../flextype/core/Serializers/PhpCodeTest.php | 34 ------ 4 files changed, 160 deletions(-) delete mode 100644 src/flextype/core/Serializers/PhpCode.php delete mode 100644 tests/src/flextype/core/Serializers/PhpCodeTest.php diff --git a/src/flextype/core/Serializers/PhpCode.php b/src/flextype/core/Serializers/PhpCode.php deleted file mode 100644 index c987b6b2..00000000 --- a/src/flextype/core/Serializers/PhpCode.php +++ /dev/null @@ -1,113 +0,0 @@ -get('flextype.settings.serializers.phpcode.encode.wrap'); - - try { - if ($wrap) { - $data = "get('flextype.settings.serializers.phpcode.decode.cache'); - - $decode = static function (string $input) { - $currentErrorLevel = error_reporting(); - error_reporting(E_ALL); - $return = null; - $eval = @eval('$return=' . $input . ';'); - $error = error_get_last(); - error_reporting($currentErrorLevel); - - if ($eval === false || $error) { - $msg = 'Decoding PhpCode failed'; - - if ($eval === false) { - $lastError = error_get_last(); - $msg .= ': ' . $lastError['message']; - } - - throw new RuntimeException($msg, 0); - } - - return $return; - }; - - if ($cache === true && registry()->get('flextype.settings.cache.enabled') === true) { - $key = $this->getCacheID($input); - - if ($dataFromCache = cache()->get($key)) { - return $dataFromCache; - } - - $data = $decode($input); - cache()->set($key, $data); - - return $data; - } - - return $decode($input); - } - - /** - * Get Cache ID for phpcode. - * - * @param string $input Input. - * - * @return string Cache ID. - * - * @access public - */ - public function getCacheID(string $input): string - { - return strings('phpcode' . $input)->hash()->toString(); - } -} diff --git a/src/flextype/core/Serializers/Serializers.php b/src/flextype/core/Serializers/Serializers.php index f9bb0c5f..addb9cc7 100644 --- a/src/flextype/core/Serializers/Serializers.php +++ b/src/flextype/core/Serializers/Serializers.php @@ -54,12 +54,4 @@ class Serializers { return new PhpArray(); } - - /** - * Create a PhpCode instance. - */ - public function phpcode(): PhpCode - { - return new PhpCode(); - } } diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 632b31d8..c59b7f0c 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -459,11 +459,6 @@ serializers: cache: true encode: wrap: true - phpcode: - decode: - cache: true - encode: - wrap: false # Parsers # diff --git a/tests/src/flextype/core/Serializers/PhpCodeTest.php b/tests/src/flextype/core/Serializers/PhpCodeTest.php deleted file mode 100644 index 54e88614..00000000 --- a/tests/src/flextype/core/Serializers/PhpCodeTest.php +++ /dev/null @@ -1,34 +0,0 @@ -assertEquals(31, strings(serializers()->phpcode()->encode(['flextype' => registry()->get("flextype.manifest.version")]))->length()); - - registry()->set('flextype.settings.serializers.phpcode.encode.wrap', true); - $this->assertEquals(47, strings(serializers()->phpcode()->encode(['flextype' => registry()->get("flextype.manifest.version")]))->length()); -}); - -test('test encode() throws exception RuntimeException', function (): void { - serializers()->phpcode()->encode(new Foo()); -})->throws(RuntimeException::class); - -test('decode', function () { - $this->assertEquals('Flextype', serializers()->phpcode()->decode('registry()->get("flextype.manifest.name")')); -}); - -test('get cache ID', function () { - $string = strings(serializers()->phpcode()->encode(['flextype' => registry()->get("flextype.manifest.version")]))->toString(); - $cache_id = serializers()->phparray() - ->getCacheID($string); - $this->assertEquals(32, strlen($cache_id)); - $this->assertNotEquals($string, $cache_id); -}); - -class Foo -{ - public function __serialize() - { - throw new RuntimeException('Encoding PhpCode failed'); - } -} \ No newline at end of file