From c703b355b8e3063abbd9d84768fd16429250d74a Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Fri, 31 May 2019 14:54:51 +0200 Subject: [PATCH] [Serializer] Remove last deprecated/obsolete paths --- UPGRADE-5.0.md | 1 + .../FrameworkExtension.php | 16 ----------- .../CacheWarmer/SerializerCacheWarmerTest.php | 9 ------ .../FrameworkExtensionTest.php | 4 --- src/Symfony/Component/Serializer/CHANGELOG.md | 1 + .../Serializer/Encoder/JsonDecode.php | 16 +---------- .../Serializer/Encoder/JsonEncode.php | 13 ++------- .../Normalizer/AbstractNormalizer.php | 26 ++--------------- .../Normalizer/AbstractObjectNormalizer.php | 11 +------- .../Normalizer/DataUriNormalizer.php | 28 +++++-------------- .../Component/Serializer/Serializer.php | 15 +--------- .../Component/Serializer/composer.json | 3 +- 12 files changed, 19 insertions(+), 124 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index e7d5edd5e2a60..2d72825836f4f 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -423,6 +423,7 @@ Serializer were removed, use the default context instead. * The `AbstractNormalizer::handleCircularReference()` method has two new `$format` and `$context` arguments. + * Removed support for instantiating a `DataUriNormalizer` with a default MIME type guesser when the `symfony/mime` component isn't installed. Translation ----------- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 98ac211a44714..7b4364455fb62 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -93,9 +93,6 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Encoder\EncoderInterface; -use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; -use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer; -use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Stopwatch\Stopwatch; @@ -1280,19 +1277,6 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder { $loader->load('serializer.xml'); - if (!class_exists(DateIntervalNormalizer::class)) { - $container->removeDefinition('serializer.normalizer.dateinterval'); - } - - if (!class_exists(ConstraintViolationListNormalizer::class)) { - $container->removeDefinition('serializer.normalizer.constraint_violation_list'); - } - - if (!class_exists(ClassDiscriminatorFromClassMetadata::class)) { - $container->removeAlias('Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface'); - $container->removeDefinition('serializer.mapping.class_discriminator_resolver'); - } - $chainLoader = $container->getDefinition('serializer.mapping.chain_loader'); if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php index ccaa64931b5c3..1ac64dcc1c8f5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php @@ -15,7 +15,6 @@ use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Component\Cache\Adapter\NullAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter; -use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader; @@ -23,10 +22,6 @@ class SerializerCacheWarmerTest extends TestCase { public function testWarmUp() { - if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) { - $this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.'); - } - $loaders = [ new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'), new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'), @@ -48,10 +43,6 @@ public function testWarmUp() public function testWarmUpWithoutLoader() { - if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) { - $this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.'); - } - $file = sys_get_temp_dir().'/cache-serializer-without-loader.php'; @unlink($file); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 65d1b8c7fa174..ceb8f61ed1966 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1033,10 +1033,6 @@ public function testDataUriNormalizerRegistered() public function testDateIntervalNormalizerRegistered() { - if (!class_exists(DateIntervalNormalizer::class)) { - $this->markTestSkipped('The DateIntervalNormalizer has been introduced in the Serializer Component version 3.4.'); - } - $container = $this->createContainerFromFile('full'); $definition = $container->getDefinition('serializer.normalizer.dateinterval'); diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index a805f0f90f462..d6fb394118470 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -16,6 +16,7 @@ CHANGELOG use the default context instead. * removed `XmlEncoder::setRootNodeName()` & `XmlEncoder::getRootNodeName()`, use the default context instead. * removed individual encoders/normalizers options as constructor arguments. + * removed support for instantiating a `DataUriNormalizer` with a default MIME type guesser when the `symfony/mime` component isn't installed. 4.3.0 ----- diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index ceedce69eef21..7048dcf173165 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -40,22 +40,8 @@ class JsonDecode implements DecoderInterface self::RECURSION_DEPTH => 512, ]; - /** - * Constructs a new JsonDecode instance. - * - * @param array $defaultContext - */ - public function __construct($defaultContext = [], int $depth = 512) + public function __construct(array $defaultContext = []) { - if (!\is_array($defaultContext)) { - @trigger_error(sprintf('Using constructor parameters that are not a default context is deprecated since Symfony 4.2, use the "%s" and "%s" keys of the context instead.', self::ASSOCIATIVE, self::RECURSION_DEPTH), E_USER_DEPRECATED); - - $defaultContext = [ - self::ASSOCIATIVE => (bool) $defaultContext, - self::RECURSION_DEPTH => $depth, - ]; - } - $this->defaultContext = array_merge($this->defaultContext, $defaultContext); } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 681e3c4941dc4..2363aead7abb1 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -26,18 +26,9 @@ class JsonEncode implements EncoderInterface self::OPTIONS => 0, ]; - /** - * @param array $defaultContext - */ - public function __construct($defaultContext = []) + public function __construct(array $defaultContext = []) { - if (!\is_array($defaultContext)) { - @trigger_error(sprintf('Passing an integer as first parameter of the "%s()" method is deprecated since Symfony 4.2, use the "json_encode_options" key of the context instead.', __METHOD__), E_USER_DEPRECATED); - - $this->defaultContext[self::OPTIONS] = (int) $defaultContext; - } else { - $this->defaultContext = array_merge($this->defaultContext, $defaultContext); - } + $this->defaultContext = array_merge($this->defaultContext, $defaultContext); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index 01db395d24b5d..c1b1b71debbb0 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -203,24 +203,14 @@ protected function isCircularReference($object, &$context) * If a circular reference handler is set, it will be called. Otherwise, a * {@class CircularReferenceException} will be thrown. * - * @final since Symfony 4.2 - * - * @param object $object - * @param string|null $format - * @param array $context + * @final * * @return mixed * * @throws CircularReferenceException */ - protected function handleCircularReference($object/*, string $format = null, array $context = []*/) + protected function handleCircularReference(object $object, string $format = null, array $context = []) { - if (\func_num_args() < 2 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) { - @trigger_error(sprintf('The "%s()" method will have two new "string $format = null" and "array $context = []" arguments in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED); - } - $format = \func_num_args() > 1 ? func_get_arg(1) : null; - $context = \func_num_args() > 2 ? func_get_arg(2) : []; - $circularReferenceHandler = $context[self::CIRCULAR_REFERENCE_HANDLER] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_HANDLER]; if ($circularReferenceHandler) { return $circularReferenceHandler($object, $format, $context); @@ -450,20 +440,10 @@ protected function denormalizeParameter(\ReflectionClass $class, \ReflectionPara } /** - * @param array $parentContext - * @param string $attribute Attribute name - * @param string|null $format - * - * @return array - * * @internal */ - protected function createChildContext(array $parentContext, $attribute/*, ?string $format */) + protected function createChildContext(array $parentContext, string $attribute, ?string $format): array { - if (\func_num_args() < 3) { - @trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED); - $format = null; - } if (isset($parentContext[self::ATTRIBUTES][$attribute])) { $parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute]; } else { diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index eb7ea7b4dc08d..5edc594828e8f 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -540,18 +540,9 @@ private function isMaxDepthReached(array $attributesMetadata, string $class, str * We must not mix up the attribute cache between parent and children. * * {@inheritdoc} - * - * @param string|null $format */ - protected function createChildContext(array $parentContext, $attribute/*, ?string $format */) + protected function createChildContext(array $parentContext, string $attribute, ?string $format): array { - if (\func_num_args() >= 3) { - $format = \func_get_arg(2); - } else { - @trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED); - $format = null; - } - $context = parent::createChildContext($parentContext, $attribute, $format); $context['cache_key'] = $this->getCacheKey($format, $context); diff --git a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php index a6ca7223b0b91..0cad3f9cf984a 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -12,8 +12,6 @@ namespace Symfony\Component\Serializer\Normalizer; use Symfony\Component\HttpFoundation\File\File; -use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; -use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as DeprecatedMimeTypeGuesserInterface; use Symfony\Component\Mime\MimeTypeGuesserInterface; use Symfony\Component\Mime\MimeTypes; use Symfony\Component\Serializer\Exception\InvalidArgumentException; @@ -38,22 +36,10 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C */ private $mimeTypeGuesser; - /** - * @param MimeTypeGuesserInterface|null $mimeTypeGuesser - */ - public function __construct($mimeTypeGuesser = null) + public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser = null) { - if ($mimeTypeGuesser instanceof DeprecatedMimeTypeGuesserInterface) { - @trigger_error(sprintf('Passing a %s to "%s()" is deprecated since Symfony 4.3, pass a "%s" instead.', DeprecatedMimeTypeGuesserInterface::class, __METHOD__, MimeTypeGuesserInterface::class), E_USER_DEPRECATED); - } elseif (null === $mimeTypeGuesser) { - if (class_exists(MimeTypes::class)) { - $mimeTypeGuesser = MimeTypes::getDefault(); - } elseif (class_exists(MimeTypeGuesser::class)) { - @trigger_error(sprintf('Passing null to "%s()" to use a default MIME type guesser without Symfony Mime installed is deprecated since Symfony 4.3. Try running "composer require symfony/mime".', __METHOD__), E_USER_DEPRECATED); - $mimeTypeGuesser = MimeTypeGuesser::getInstance(); - } - } elseif (!$mimeTypeGuesser instanceof MimeTypes) { - throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be an instance of "%s" or null, %s given.', __METHOD__, MimeTypes::class, \is_object($mimeTypeGuesser) ? \get_class($mimeTypeGuesser) : \gettype($mimeTypeGuesser))); + if (!$mimeTypeGuesser && class_exists(MimeTypes::class)) { + $mimeTypeGuesser = MimeTypes::getDefault(); } $this->mimeTypeGuesser = $mimeTypeGuesser; @@ -112,6 +98,10 @@ public function denormalize($data, $class, $format = null, array $context = []) try { switch ($class) { case 'Symfony\Component\HttpFoundation\File\File': + if (!class_exists(File::class)) { + throw new InvalidArgumentException(sprintf('Cannot denormalize to a "%s" without the HttpFoundation component installed. Try running "composer require symfony/http-foundation".', File::class)); + } + return new File($data, false); case 'SplFileObject': @@ -154,10 +144,6 @@ private function getMimeType(\SplFileInfo $object) return $object->getMimeType(); } - if ($this->mimeTypeGuesser instanceof DeprecatedMimeTypeGuesserInterface && $mimeType = $this->mimeTypeGuesser->guess($object->getPathname())) { - return $mimeType; - } - if ($this->mimeTypeGuesser && $mimeType = $this->mimeTypeGuesser->guessMimeType($object->getPathname())) { return $mimeType; } diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 01b0f3c3a768e..c5b4eca7d0671 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -56,12 +56,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface */ protected $decoder; - /** - * @internal since Symfony 4.1 - */ - protected $normalizers = []; - - private $cachedNormalizers; + private $normalizers = []; private $denormalizerCache = []; private $normalizerCache = []; @@ -220,10 +215,6 @@ public function supportsDenormalization($data, $type, $format = null, array $con */ private function getNormalizer($data, ?string $format, array $context) { - if ($this->cachedNormalizers !== $this->normalizers) { - $this->cachedNormalizers = $this->normalizers; - $this->denormalizerCache = $this->normalizerCache = []; - } $type = \is_object($data) ? \get_class($data) : 'native-'.\gettype($data); if (!isset($this->normalizerCache[$format][$type])) { @@ -263,10 +254,6 @@ private function getNormalizer($data, ?string $format, array $context) */ private function getDenormalizer($data, string $class, ?string $format, array $context) { - if ($this->cachedNormalizers !== $this->normalizers) { - $this->cachedNormalizers = $this->normalizers; - $this->denormalizerCache = $this->normalizerCache = []; - } if (!isset($this->denormalizerCache[$format][$class])) { $this->denormalizerCache[$format][$class] = []; diff --git a/src/Symfony/Component/Serializer/composer.json b/src/Symfony/Component/Serializer/composer.json index acf2d170c1b70..ef218ec0fbaeb 100644 --- a/src/Symfony/Component/Serializer/composer.json +++ b/src/Symfony/Component/Serializer/composer.json @@ -24,6 +24,7 @@ "symfony/config": "^4.4|^5.0", "symfony/property-access": "^4.4|^5.0", "symfony/http-foundation": "^4.4|^5.0", + "symfony/mime": "^4.4|^5.0", "symfony/cache": "^4.4|^5.0", "symfony/property-info": "^4.4|^5.0", "symfony/validator": "^4.4|^5.0", @@ -45,7 +46,7 @@ "symfony/yaml": "For using the default YAML mapping loader.", "symfony/config": "For using the XML mapping loader.", "symfony/property-access": "For using the ObjectNormalizer.", - "symfony/http-foundation": "For using a MIME type guesser within the DataUriNormalizer.", + "symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.", "doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.", "doctrine/cache": "For using the default cached annotation reader and metadata cache." }, 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