From f8bf9738f0cb2ed1b535785699d1d37dc0ea78d7 Mon Sep 17 00:00:00 2001 From: renanbr Date: Thu, 31 Jan 2019 13:39:06 +0100 Subject: [PATCH] Drop \Serializable --- src/Symfony/Component/Config/CHANGELOG.md | 1 + .../Resource/ClassExistenceResource.php | 16 ++++--------- .../Config/Resource/ComposerResource.php | 20 +++------------- .../Config/Resource/DirectoryResource.php | 20 +++------------- .../Config/Resource/FileExistenceResource.php | 20 +++------------- .../Config/Resource/FileResource.php | 20 +++------------- .../Config/Resource/GlobResource.php | 16 ++++--------- .../Resource/ReflectionClassResource.php | 16 ++++--------- .../Config/ResourceCheckerConfigCache.php | 10 +++++++- .../DependencyInjection/CHANGELOG.md | 1 + .../Config/ContainerParametersResource.php | 20 +++------------- src/Symfony/Component/Form/CHANGELOG.md | 2 +- src/Symfony/Component/Form/FormError.php | 24 +------------------ .../DataCollector/FormDataCollectorTest.php | 2 +- src/Symfony/Component/HttpKernel/CHANGELOG.md | 1 + .../HttpKernel/Debug/FileLinkFormatter.php | 16 +++++-------- 16 files changed, 51 insertions(+), 154 deletions(-) diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index 2e3b31e3146d7..122184021c3bf 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()` + * made `Resource\*` classes final and not implement `Serializable` anymore 4.2.0 ----- diff --git a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php index 035b3ce980035..51154cfd6a41f 100644 --- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php @@ -18,8 +18,10 @@ * The resource must be a fully-qualified class name. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ -class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializable +class ClassExistenceResource implements SelfCheckingResourceInterface { private $resource; private $exists; @@ -97,21 +99,13 @@ public function isFresh($timestamp) /** * @internal */ - public function serialize() + public function __sleep(): array { if (null === $this->exists) { $this->isFresh(0); } - return serialize([$this->resource, $this->exists]); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - list($this->resource, $this->exists) = unserialize($serialized); + return ['resource', 'exists']; } /** diff --git a/src/Symfony/Component/Config/Resource/ComposerResource.php b/src/Symfony/Component/Config/Resource/ComposerResource.php index c826d1bb75127..db6b04c812c57 100644 --- a/src/Symfony/Component/Config/Resource/ComposerResource.php +++ b/src/Symfony/Component/Config/Resource/ComposerResource.php @@ -15,8 +15,10 @@ * ComposerResource tracks the PHP version and Composer dependencies. * * @author Nicolas Grekas + * + * @final since Symfony 4.3 */ -class ComposerResource implements SelfCheckingResourceInterface, \Serializable +class ComposerResource implements SelfCheckingResourceInterface { private $vendors; @@ -51,22 +53,6 @@ public function isFresh($timestamp) return self::$runtimeVendors === $this->vendors; } - /** - * @internal - */ - public function serialize() - { - return serialize($this->vendors); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - $this->vendors = unserialize($serialized); - } - private static function refresh() { self::$runtimeVendors = []; diff --git a/src/Symfony/Component/Config/Resource/DirectoryResource.php b/src/Symfony/Component/Config/Resource/DirectoryResource.php index d657abcbae204..3d703db7f6ebe 100644 --- a/src/Symfony/Component/Config/Resource/DirectoryResource.php +++ b/src/Symfony/Component/Config/Resource/DirectoryResource.php @@ -15,8 +15,10 @@ * DirectoryResource represents a resources stored in a subdirectory tree. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ -class DirectoryResource implements SelfCheckingResourceInterface, \Serializable +class DirectoryResource implements SelfCheckingResourceInterface { private $resource; private $pattern; @@ -103,20 +105,4 @@ public function isFresh($timestamp) return true; } - - /** - * @internal - */ - public function serialize() - { - return serialize([$this->resource, $this->pattern]); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - list($this->resource, $this->pattern) = unserialize($serialized); - } } diff --git a/src/Symfony/Component/Config/Resource/FileExistenceResource.php b/src/Symfony/Component/Config/Resource/FileExistenceResource.php index 8c65729c45a10..57234161588c7 100644 --- a/src/Symfony/Component/Config/Resource/FileExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/FileExistenceResource.php @@ -18,8 +18,10 @@ * The resource can be a file or a directory. * * @author Charles-Henri Bruyand + * + * @final since Symfony 4.3 */ -class FileExistenceResource implements SelfCheckingResourceInterface, \Serializable +class FileExistenceResource implements SelfCheckingResourceInterface { private $resource; @@ -57,20 +59,4 @@ public function isFresh($timestamp) { return file_exists($this->resource) === $this->exists; } - - /** - * @internal - */ - public function serialize() - { - return serialize([$this->resource, $this->exists]); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - list($this->resource, $this->exists) = unserialize($serialized); - } } diff --git a/src/Symfony/Component/Config/Resource/FileResource.php b/src/Symfony/Component/Config/Resource/FileResource.php index 94ec2c729a994..95fe8a0bf802c 100644 --- a/src/Symfony/Component/Config/Resource/FileResource.php +++ b/src/Symfony/Component/Config/Resource/FileResource.php @@ -17,8 +17,10 @@ * The resource can be a file or a directory. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ -class FileResource implements SelfCheckingResourceInterface, \Serializable +class FileResource implements SelfCheckingResourceInterface { /** * @var string|false @@ -62,20 +64,4 @@ public function isFresh($timestamp) { return false !== ($filemtime = @filemtime($this->resource)) && $filemtime <= $timestamp; } - - /** - * @internal - */ - public function serialize() - { - return serialize($this->resource); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - $this->resource = unserialize($serialized); - } } diff --git a/src/Symfony/Component/Config/Resource/GlobResource.php b/src/Symfony/Component/Config/Resource/GlobResource.php index 5581e67ecaae9..fce8f6e2062a0 100644 --- a/src/Symfony/Component/Config/Resource/GlobResource.php +++ b/src/Symfony/Component/Config/Resource/GlobResource.php @@ -20,8 +20,10 @@ * Only existence/removal is tracked (not mtimes.) * * @author Nicolas Grekas + * + * @final since Symfony 4.3 */ -class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface, \Serializable +class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface { private $prefix; private $pattern; @@ -80,21 +82,13 @@ public function isFresh($timestamp) /** * @internal */ - public function serialize() + public function __sleep(): array { if (null === $this->hash) { $this->hash = $this->computeHash(); } - return serialize([$this->prefix, $this->pattern, $this->recursive, $this->hash, $this->forExclusion, $this->excludedPrefixes]); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - list($this->prefix, $this->pattern, $this->recursive, $this->hash, $this->forExclusion, $this->excludedPrefixes) = unserialize($serialized) + [4 => false, []]; + return ['prefix', 'pattern', 'recursive', 'hash', 'forExclusion', 'excludedPrefixes']; } public function getIterator() diff --git a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php index a7e73becf55f4..16cdb6ac0c379 100644 --- a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php +++ b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php @@ -17,8 +17,10 @@ /** * @author Nicolas Grekas + * + * @final since Symfony 4.3 */ -class ReflectionClassResource implements SelfCheckingResourceInterface, \Serializable +class ReflectionClassResource implements SelfCheckingResourceInterface { private $files = []; private $className; @@ -61,22 +63,14 @@ public function __toString() /** * @internal */ - public function serialize() + public function __sleep(): array { if (null === $this->hash) { $this->hash = $this->computeHash(); $this->loadFiles($this->classReflector); } - return serialize([$this->files, $this->className, $this->hash]); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - list($this->files, $this->className, $this->hash) = unserialize($serialized); + return ['files', 'className', 'hash']; } private function loadFiles(\ReflectionClass $class) diff --git a/src/Symfony/Component/Config/ResourceCheckerConfigCache.php b/src/Symfony/Component/Config/ResourceCheckerConfigCache.php index ef18072844eaa..34dc35d5f51f8 100644 --- a/src/Symfony/Component/Config/ResourceCheckerConfigCache.php +++ b/src/Symfony/Component/Config/ResourceCheckerConfigCache.php @@ -158,7 +158,7 @@ private function safelyUnserialize($file) $meta = false; $content = file_get_contents($file); $signalingException = new \UnexpectedValueException(); - $prevUnserializeHandler = ini_set('unserialize_callback_func', ''); + $prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback'); $prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler, $signalingException) { if (__FILE__ === $file) { throw $signalingException; @@ -180,4 +180,12 @@ private function safelyUnserialize($file) return $meta; } + + /** + * @internal + */ + public static function handleUnserializeCallback($class) + { + trigger_error('Class not found: '.$class); + } } diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index d76aeb147ba4c..87739fc9753da 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * added `%env(default:...)%` processor to fallback to a default value * added `%env(nullable:...)%` processor to allow empty variables to be processed as null values * added support for deprecating aliases + * made `ContainerParametersResource` final and not implement `Serializable` anymore 4.2.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Config/ContainerParametersResource.php b/src/Symfony/Component/DependencyInjection/Config/ContainerParametersResource.php index 7560c3356d978..e9a4fffe2ad1c 100644 --- a/src/Symfony/Component/DependencyInjection/Config/ContainerParametersResource.php +++ b/src/Symfony/Component/DependencyInjection/Config/ContainerParametersResource.php @@ -17,8 +17,10 @@ * Tracks container parameters. * * @author Maxime Steinhausser + * + * @final since Symfony 4.3 */ -class ContainerParametersResource implements ResourceInterface, \Serializable +class ContainerParametersResource implements ResourceInterface { private $parameters; @@ -38,22 +40,6 @@ public function __toString() return 'container_parameters_'.md5(serialize($this->parameters)); } - /** - * @internal - */ - public function serialize() - { - return serialize($this->parameters); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - $this->parameters = unserialize($serialized); - } - /** * @return array Tracked parameters */ diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 142a1d92fa85e..127406bcdeddb 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG option is set to `single_text` * added `block_prefix` option to `BaseType`. * added `help_html` option to display the `help` text as HTML. + * `FormError` doesn't implement `Serializable` anymore * added `label_translation_parameters`, `attr_translation_parameters`, `help_translation_parameters` options to `FormType` to pass translation parameters to form labels, attributes (`placeholder` and `title`) and help text respectively. The passed parameters will replace placeholders in translation messages. @@ -32,7 +33,6 @@ CHANGELOG } ``` - 4.2.0 ----- diff --git a/src/Symfony/Component/Form/FormError.php b/src/Symfony/Component/Form/FormError.php index 6724ddc03c510..4e01a62e419a2 100644 --- a/src/Symfony/Component/Form/FormError.php +++ b/src/Symfony/Component/Form/FormError.php @@ -18,7 +18,7 @@ * * @author Bernhard Schussek */ -class FormError implements \Serializable +class FormError { protected $messageTemplate; protected $messageParameters; @@ -133,26 +133,4 @@ public function getOrigin() { return $this->origin; } - - /** - * @internal - */ - public function serialize() - { - return serialize([ - $this->message, - $this->messageTemplate, - $this->messageParameters, - $this->messagePluralization, - $this->cause, - ]); - } - - /** - * @internal - */ - public function unserialize($serialized) - { - list($this->message, $this->messageTemplate, $this->messageParameters, $this->messagePluralization, $this->cause) = unserialize($serialized, ['allowed_classes' => false]); - } } diff --git a/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php b/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php index 2ca0f95f3c6e3..0603c38e05cd5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php @@ -448,7 +448,7 @@ public function testSerializeWithFormAddedMultipleTimes() $this->dataCollector->collectViewVariables($form2View); $this->dataCollector->buildFinalFormTree($form2, $form2View); - $this->dataCollector->serialize(); + serialize($this->dataCollector); } public function testFinalFormReliesOnFormViewStructure() diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 5b974735e2647..2d1cfc4ba1d9e 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * increased the priority of `Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener` * made `Symfony\Component\HttpKernel\EventListenerLocaleListener` set the default locale early + * made `FileLinkFormatter` final and not implement `Serializable` anymore 4.2.0 ----- diff --git a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php index 9476d50486f87..d83f7920df055 100644 --- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php +++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php @@ -20,8 +20,10 @@ * Formats debug file links. * * @author Jérémy Romey + * + * @final since Symfony 4.3 */ -class FileLinkFormatter implements \Serializable +class FileLinkFormatter { private $fileLinkFormat; private $requestStack; @@ -64,17 +66,11 @@ public function format($file, $line) /** * @internal */ - public function serialize() + public function __sleep(): array { - return serialize($this->getFileLinkFormat()); - } + $this->getFileLinkFormat(); - /** - * @internal - */ - public function unserialize($serialized) - { - $this->fileLinkFormat = unserialize($serialized, ['allowed_classes' => false]); + return ['fileLinkFormat']; } /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy