Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 42061be

Browse filesBrowse files
committed
[Serializer] Remove deprecation layer
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 76ee4a5 commit 42061be
Copy full SHA for 42061be

15 files changed

+56
-537
lines changed

‎src/Symfony/Component/Serializer/Annotation/Context.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/Context.php
+9-37Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,58 +25,30 @@
2525
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
2626
final class Context
2727
{
28-
private $context;
29-
private $normalizationContext;
30-
private $denormalizationContext;
31-
private $groups;
28+
private array $groups;
3229

3330
/**
3431
* @param string|string[] $groups
3532
*
3633
* @throws InvalidArgumentException
3734
*/
38-
public function __construct(array $options = [], array $context = [], array $normalizationContext = [], array $denormalizationContext = [], $groups = [])
39-
{
40-
if (!$context) {
41-
if (!array_intersect((array_keys($options)), ['normalizationContext', 'groups', 'context', 'value', 'denormalizationContext'])) {
42-
// gracefully supports context as first, unnamed attribute argument if it cannot be confused with Doctrine-style options
43-
$context = $options;
44-
} else {
45-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array of properties as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
46-
47-
// If at least one of the options match, it's likely to be Doctrine-style options. Search for the context inside:
48-
$context = $options['value'] ?? $options['context'] ?? [];
49-
}
50-
}
51-
if (!\is_string($groups) && !\is_array($groups)) {
52-
throw new \TypeError(sprintf('"%s": Expected parameter $groups to be a string or an array of strings, got "%s".', __METHOD__, get_debug_type($groups)));
53-
}
54-
55-
$normalizationContext = $options['normalizationContext'] ?? $normalizationContext;
56-
$denormalizationContext = $options['denormalizationContext'] ?? $denormalizationContext;
57-
58-
foreach (compact(['context', 'normalizationContext', 'denormalizationContext']) as $key => $value) {
59-
if (!\is_array($value)) {
60-
throw new InvalidArgumentException(sprintf('Option "%s" of annotation "%s" must be an array.', $key, static::class));
61-
}
62-
}
63-
35+
public function __construct(
36+
private array $context = [],
37+
private array $normalizationContext = [],
38+
private array $denormalizationContext = [],
39+
string|array $groups = [],
40+
) {
6441
if (!$context && !$normalizationContext && !$denormalizationContext) {
6542
throw new InvalidArgumentException(sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options of annotation "%s" must be provided as a non-empty array.', static::class));
6643
}
6744

68-
$groups = (array) ($options['groups'] ?? $groups);
45+
$this->groups = (array) $groups;
6946

70-
foreach ($groups as $group) {
47+
foreach ($this->groups as $group) {
7148
if (!\is_string($group)) {
7249
throw new InvalidArgumentException(sprintf('Parameter "groups" of annotation "%s" must be a string or an array of strings. Got "%s".', static::class, get_debug_type($group)));
7350
}
7451
}
75-
76-
$this->context = $context;
77-
$this->normalizationContext = $normalizationContext;
78-
$this->denormalizationContext = $denormalizationContext;
79-
$this->groups = $groups;
8052
}
8153

8254
public function getContext(): array

‎src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php
+4-26Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,19 @@
2626
class DiscriminatorMap
2727
{
2828
/**
29-
* @var string
30-
*/
31-
private $typeProperty;
32-
33-
/**
34-
* @var array
35-
*/
36-
private $mapping;
37-
38-
/**
39-
* @param string $typeProperty
40-
*
4129
* @throws InvalidArgumentException
4230
*/
43-
public function __construct($typeProperty, array $mapping = null)
44-
{
45-
if (\is_array($typeProperty)) {
46-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
47-
48-
$mapping = $typeProperty['mapping'] ?? null;
49-
$typeProperty = $typeProperty['typeProperty'] ?? null;
50-
} elseif (!\is_string($typeProperty)) {
51-
throw new \TypeError(sprintf('"%s": Argument $typeProperty was expected to be a string or array, got "%s".', __METHOD__, get_debug_type($typeProperty)));
52-
}
53-
31+
public function __construct(
32+
private string $typeProperty,
33+
private array $mapping,
34+
) {
5435
if (empty($typeProperty)) {
5536
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" of annotation "%s" cannot be empty.', static::class));
5637
}
5738

5839
if (empty($mapping)) {
5940
throw new InvalidArgumentException(sprintf('Parameter "mapping" of annotation "%s" cannot be empty.', static::class));
6041
}
61-
62-
$this->typeProperty = $typeProperty;
63-
$this->mapping = $mapping;
6442
}
6543

6644
public function getTypeProperty(): string

‎src/Symfony/Component/Serializer/Annotation/Groups.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/Groups.php
+5-14Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,26 @@ class Groups
2828
/**
2929
* @var string[]
3030
*/
31-
private $groups;
31+
private array $groups;
3232

3333
/**
3434
* @param string|string[] $groups
3535
*
3636
* @throws InvalidArgumentException
3737
*/
38-
public function __construct($groups)
38+
public function __construct(string|array $groups)
3939
{
40-
if (\is_string($groups)) {
41-
$groups = (array) $groups;
42-
} elseif (!\is_array($groups)) {
43-
throw new \TypeError(sprintf('"%s": Parameter $groups is expected to be a string or an array of strings, got "%s".', __METHOD__, get_debug_type($groups)));
44-
} elseif (isset($groups['value'])) {
45-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array of properties as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
40+
$this->groups = (array) $groups;
4641

47-
$groups = (array) $groups['value'];
48-
}
49-
if (empty($groups)) {
42+
if (empty($this->groups)) {
5043
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', static::class));
5144
}
5245

53-
foreach ($groups as $group) {
46+
foreach ($this->groups as $group) {
5447
if (!\is_string($group)) {
5548
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', static::class));
5649
}
5750
}
58-
59-
$this->groups = $groups;
6051
}
6152

6253
/**

‎src/Symfony/Component/Serializer/Annotation/MaxDepth.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/MaxDepth.php
+2-21Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,11 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
class MaxDepth
2727
{
28-
/**
29-
* @var int
30-
*/
31-
private $maxDepth;
32-
33-
/**
34-
* @param int $maxDepth
35-
*/
36-
public function __construct($maxDepth)
28+
public function __construct(private int $maxDepth)
3729
{
38-
if (\is_array($maxDepth)) {
39-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
40-
41-
if (!isset($maxDepth['value'])) {
42-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', static::class));
43-
}
44-
$maxDepth = $maxDepth['value'];
45-
}
46-
47-
if (!\is_int($maxDepth) || $maxDepth <= 0) {
30+
if ($maxDepth <= 0) {
4831
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', static::class));
4932
}
50-
51-
$this->maxDepth = $maxDepth;
5233
}
5334

5435
public function getMaxDepth()

‎src/Symfony/Component/Serializer/Annotation/SerializedName.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/SerializedName.php
+2-21Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,11 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
final class SerializedName
2727
{
28-
/**
29-
* @var string
30-
*/
31-
private $serializedName;
32-
33-
/**
34-
* @param string $serializedName
35-
*/
36-
public function __construct($serializedName)
28+
public function __construct(private string $serializedName)
3729
{
38-
if (\is_array($serializedName)) {
39-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
40-
41-
if (!isset($serializedName['value'])) {
42-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', static::class));
43-
}
44-
$serializedName = $serializedName['value'];
45-
}
46-
47-
if (!\is_string($serializedName) || empty($serializedName)) {
30+
if ('' === $serializedName) {
4831
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a non-empty string.', static::class));
4932
}
50-
51-
$this->serializedName = $serializedName;
5233
}
5334

5435
public function getSerializedName(): string

‎src/Symfony/Component/Serializer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
6.0
5+
---
6+
7+
* Remove `ArrayDenormalizer::setSerializer()`, call `setDenormalizer()` instead
8+
* Remove the ability to create instances of the annotation classes by passing an array of parameters, use named arguments instead
9+
410
5.3
511
---
612

‎src/Symfony/Component/Serializer/DependencyInjection/SerializerPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/DependencyInjection/SerializerPass.php
+6-21Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,21 @@ class SerializerPass implements CompilerPassInterface
2727
{
2828
use PriorityTaggedServiceTrait;
2929

30-
private $serializerService;
31-
private $normalizerTag;
32-
private $encoderTag;
33-
34-
public function __construct(string $serializerService = 'serializer', string $normalizerTag = 'serializer.normalizer', string $encoderTag = 'serializer.encoder')
35-
{
36-
if (0 < \func_num_args()) {
37-
trigger_deprecation('symfony/serializer', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
38-
}
39-
40-
$this->serializerService = $serializerService;
41-
$this->normalizerTag = $normalizerTag;
42-
$this->encoderTag = $encoderTag;
43-
}
44-
4530
public function process(ContainerBuilder $container)
4631
{
47-
if (!$container->hasDefinition($this->serializerService)) {
32+
if (!$container->hasDefinition('serializer')) {
4833
return;
4934
}
5035

51-
if (!$normalizers = $this->findAndSortTaggedServices($this->normalizerTag, $container)) {
52-
throw new RuntimeException(sprintf('You must tag at least one service as "%s" to use the "%s" service.', $this->normalizerTag, $this->serializerService));
36+
if (!$normalizers = $this->findAndSortTaggedServices('serializer.normalizer', $container)) {
37+
throw new RuntimeException('You must tag at least one service as "serializer.normalizer" to use the "serializer" service.');
5338
}
5439

55-
$serializerDefinition = $container->getDefinition($this->serializerService);
40+
$serializerDefinition = $container->getDefinition('serializer');
5641
$serializerDefinition->replaceArgument(0, $normalizers);
5742

58-
if (!$encoders = $this->findAndSortTaggedServices($this->encoderTag, $container)) {
59-
throw new RuntimeException(sprintf('You must tag at least one service as "%s" to use the "%s" service.', $this->encoderTag, $this->serializerService));
43+
if (!$encoders = $this->findAndSortTaggedServices('serializer.encoder', $container)) {
44+
throw new RuntimeException('You must tag at least one service as "serializer.encoder" to use the "serializer" service.');
6045
}
6146

6247
$serializerDefinition->replaceArgument(1, $encoders);

‎src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php
+1-22Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
use Symfony\Component\Serializer\Exception\BadMethodCallException;
1515
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1616
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
17-
use Symfony\Component\Serializer\Serializer;
18-
use Symfony\Component\Serializer\SerializerAwareInterface;
19-
use Symfony\Component\Serializer\SerializerInterface;
2017

2118
/**
2219
* Denormalizes arrays of objects.
@@ -25,7 +22,7 @@
2522
*
2623
* @final
2724
*/
28-
class ArrayDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface, SerializerAwareInterface, CacheableSupportsMethodInterface
25+
class ArrayDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface
2926
{
3027
use DenormalizerAwareTrait;
3128

@@ -73,24 +70,6 @@ public function supportsDenormalization($data, string $type, string $format = nu
7370
&& $this->denormalizer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
7471
}
7572

76-
/**
77-
* {@inheritdoc}
78-
*
79-
* @deprecated call setDenormalizer() instead
80-
*/
81-
public function setSerializer(SerializerInterface $serializer)
82-
{
83-
if (!$serializer instanceof DenormalizerInterface) {
84-
throw new InvalidArgumentException('Expected a serializer that also implements DenormalizerInterface.');
85-
}
86-
87-
if (Serializer::class !== debug_backtrace()[1]['class'] ?? null) {
88-
trigger_deprecation('symfony/serializer', '5.3', 'Calling "%s" is deprecated. Please call setDenormalizer() instead.');
89-
}
90-
91-
$this->setDenormalizer($serializer);
92-
}
93-
9473
/**
9574
* {@inheritdoc}
9675
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.