Skip to content

Navigation Menu

Sign in
Appearance settings

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 56034b5

Browse filesBrowse files
derrabusnicolas-grekas
authored andcommitted
[Serializer] Remove deprecation layer
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 99befff commit 56034b5
Copy full SHA for 56034b5

15 files changed

+56
-330
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/Context.php
+9-34Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +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 = [], string|array $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-
52-
$normalizationContext = $options['normalizationContext'] ?? $normalizationContext;
53-
$denormalizationContext = $options['denormalizationContext'] ?? $denormalizationContext;
54-
55-
foreach (compact(['context', 'normalizationContext', 'denormalizationContext']) as $key => $value) {
56-
if (!\is_array($value)) {
57-
throw new InvalidArgumentException(sprintf('Option "%s" of annotation "%s" must be an array.', $key, static::class));
58-
}
59-
}
60-
35+
public function __construct(
36+
private array $context = [],
37+
private array $normalizationContext = [],
38+
private array $denormalizationContext = [],
39+
string|array $groups = [],
40+
) {
6141
if (!$context && !$normalizationContext && !$denormalizationContext) {
6242
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));
6343
}
6444

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

67-
foreach ($groups as $group) {
47+
foreach ($this->groups as $group) {
6848
if (!\is_string($group)) {
6949
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)));
7050
}
7151
}
72-
73-
$this->context = $context;
74-
$this->normalizationContext = $normalizationContext;
75-
$this->denormalizationContext = $denormalizationContext;
76-
$this->groups = $groups;
7752
}
7853

7954
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-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,17 @@
2525
#[\Attribute(\Attribute::TARGET_CLASS)]
2626
class DiscriminatorMap
2727
{
28-
private $typeProperty;
29-
private $mapping;
30-
31-
public function __construct(string $typeProperty, array $mapping)
32-
{
28+
public function __construct(
29+
private string $typeProperty,
30+
private array $mapping,
31+
) {
3332
if (empty($typeProperty)) {
3433
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" of annotation "%s" cannot be empty.', static::class));
3534
}
3635

3736
if (empty($mapping)) {
3837
throw new InvalidArgumentException(sprintf('Parameter "mapping" of annotation "%s" cannot be empty.', static::class));
3938
}
40-
41-
$this->typeProperty = $typeProperty;
42-
$this->mapping = $mapping;
4339
}
4440

4541
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
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,24 @@ class Groups
2828
/**
2929
* @var string[]
3030
*/
31-
private $groups;
31+
private array $groups;
3232

3333
/**
3434
* @param string|string[] $groups
3535
*/
3636
public function __construct(string|array $groups)
3737
{
38-
$groups = (array) $groups;
38+
$this->groups = (array) $groups;
3939

40-
if (empty($groups)) {
40+
if (empty($this->groups)) {
4141
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', static::class));
4242
}
4343

44-
foreach ($groups as $group) {
44+
foreach ($this->groups as $group) {
4545
if (!\is_string($group) || '' === $group) {
4646
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of non-empty strings.', static::class));
4747
}
4848
}
49-
50-
$this->groups = $groups;
5149
}
5250

5351
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/MaxDepth.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
class MaxDepth
2727
{
28-
private $maxDepth;
29-
30-
public function __construct(int $maxDepth)
31-
{
28+
public function __construct(private int $maxDepth) {
3229
if ($maxDepth <= 0) {
3330
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', static::class));
3431
}
35-
36-
$this->maxDepth = $maxDepth;
3732
}
3833

3934
public function getMaxDepth()

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/SerializedName.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
final class SerializedName
2727
{
28-
private $serializedName;
29-
30-
public function __construct(string $serializedName)
28+
public function __construct(private string $serializedName)
3129
{
3230
if (empty($serializedName)) {
3331
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a non-empty string.', static::class));
3432
}
35-
36-
$this->serializedName = $serializedName;
3733
}
3834

3935
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(mixed $data, string $type, string $forma
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.