Skip to content

[Serializer] Remove last deprecated/obsolete paths #31771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
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;

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'),
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
16 changes: 1 addition & 15 deletions src/Symfony/Component/Serializer/Encoder/JsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 2 additions & 11 deletions src/Symfony/Component/Serializer/Encoder/JsonEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
26 changes: 3 additions & 23 deletions src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have null as default, otherwise that's a hard BC break

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is internal. That should be fine, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@internal is not transitive
once all are correctly annotated on 4.4, sure :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 2b8e441

{
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);

Expand Down
28 changes: 7 additions & 21 deletions src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 1 addition & 14 deletions src/Symfony/Component/Serializer/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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] = [];

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Serializer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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."
},
Expand Down