8000 Merge branch '6.4' into 7.0 · symfony/symfony@5958047 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5958047

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Validator] Deprecate annotations in favor of attributes More intuitive Logic Exception message [Serializer] Deprecate annotations in favor of attributes
2 parents e377224 + 8e36ac6 commit 5958047

File tree

86 files changed

+829
-514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+829
-514
lines changed

UPGRADE-6.4.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ Security
7171
* `UserValueResolver` no longer implements `ArgumentValueResolverInterface`
7272
* Make `PersistentToken` immutable
7373
* Deprecate accepting only `DateTime` for `TokenProviderInterface::updateToken()`, use `DateTimeInterface` instead
74+
75+
Serializer
76+
----------
77+
78+
* Deprecate Doctrine annotations support in favor of native attributes
79+
* Deprecate passing an annotation reader to the constructor of `AnnotationLoader`
80+
81+
Validator
82+
---------
83+
84+
* Deprecate Doctrine annotations support in favor of native attributes
85+
* Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader`
86+
* Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()`
87+
* Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`

src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use Symfony\Component\Validator\Mapping\ClassMetadata;
2929
use Symfony\Component\Validator\Mapping\PropertyMetadata;
3030
use Symfony\Component\Validator\Mapping\TraversalStrategy;
31-
use Symfony\Component\Validator\Tests\Fixtures\Entity;
31+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
3232
use Symfony\Component\Validator\Validation;
3333

3434
/**
@@ -40,7 +40,6 @@ public function testLoadClassMetadata()
4040
{
4141
$validator = Validation::createValidatorBuilder()
4242
->enableAnnotationMapping(true)
43-
->addDefaultDoctrineAnnotationReader()
4443
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
4544
->getValidator()
4645
;
@@ -144,7 +143,6 @@ public function testExtractEnum()
144143
$validator = Validation::createValidatorBuilder()
145144
->addMethodMapping('loadValidatorMetadata')
146145
->enableAnnotationMapping(true)
147-
->addDefaultDoctrineAnnotationReader()
148146
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
149147
->getValidator()
150148
;
@@ -162,7 +160,6 @@ public function testFieldMappingsConfiguration()
162160
{
163161
$validator = Validation::createValidatorBuilder()
164162
->enableAnnotationMapping(true)
165-
->addDefaultDoctrineAnnotationReader()
166163
->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml'])
167164
->addLoader(
168165
new DoctrineLoader(
@@ -204,7 +201,6 @@ public function testClassNoAutoMapping()
204201
{
205202
$validator = Validation::createValidatorBuilder()
206203
->enableAnnotationMapping(true)
207-
->addDefaultDoctrineAnnotationReader()
208204
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{.*}'))
209205
->getValidator();
210206

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@
4141
"symfony/uid": "^6.4|^7.0",
4242
"symfony/validator": "^6.4|^7.0",
4343
"symfony/var-dumper": "^6.4|^7.0",
44-
"doctrine/annotations": "^1.13.1|^2",
4544
"doctrine/collections": "^1.0|^2.0",
4645
"doctrine/data-fixtures": "^1.1",
4746
"doctrine/dbal": "^3.6",
4847
"doctrine/orm": "^2.15",
4948
"psr/log": "^1|^2|^3"
5049
},
5150
"conflict": {
52-
"doctrine/annotations": "<1.13.1",
5351
"doctrine/dbal": "<3.6",
5452
"doctrine/lexer": "<1.1",
5553
"doctrine/orm": "<2.15",

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/SerializerModelFixture.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
*/
1010
class SerializerModelFixture
1111
{
12-
/**
13-
* @Groups({"read"})
14-
*/
12+
#[Groups(['read'])]
1513
public $name = 'howdy';
1614

1715
public $title = 'fixture';

src/Symfony/Bridge/Twig/Tests/Extension/SerializerExtensionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

14-
use Doctrine\Common\Annotations\AnnotationReader;
1514
use PHPUnit\Framework\TestCase;
1615
use Symfony\Bridge\Twig\Extension\SerializerExtension;
1716
use Symfony\Bridge\Twig\Extension\SerializerRuntime;
@@ -50,7 +49,7 @@ public static function serializerDataProvider(): \Generator
5049

5150
private function getTwig(string $template): Environment
5251
{
53-
$meta = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
52+
$meta = new ClassMetadataFactory(new AnnotationLoader());
5453
$runtime = new SerializerRuntime(new Serializer([new ObjectNormalizer($meta)], [new JsonEncoder(), new YamlEncoder()]));
5554

5655
$mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"twig/twig": "^2.13|^3.0.4"
2222
},
2323
"require-dev": {
24-
"doctrine/annotations": "^1.12|^2",
2524
"egulias/email-validator": "^2.1.10|^3|^4",
2625
"league/html-to-markdown": "^5.0",
2726
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
@@ -62,6 +61,7 @@
6261
"symfony/http-foundation": "<6.4",
6362
"symfony/http-kernel": "<6.4",
6463
"symfony/mime": "<6.4",
64+
"symfony/serializer": "<6.2",
6565
"symfony/translation": "<6.4",
6666
"symfony/workflow": "<6.4"
6767
},

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
178178
use Symfony\Component\Validator\ObjectInitializerInterface;
179179
use Symfony\Component\Validator\Validation;
180+
use Symfony\Component\Validator\ValidatorBuilder;
180181
use Symfony\Component\Webhook\Controller\WebhookController;
181182
use Symfony\Component\WebLink\HttpHeaderSerializer;
182183
use Symfony\Component\Workflow;

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testWarmUp()
2626
$validatorBuilder->addXmlMapping(__DIR__.'/../Fixtures/Validation/Resources/person.xml');
2727
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/author.yml');
2828
$validatorBuilder->addMethodMapping('loadValidatorMetadata');
29-
$validatorBuilder->enableAnnotationMapping(true)->addDefaultDoctrineAnnotationReader();
29+
$validatorBuilder->enableAnnotationMapping();
3030

3131
$file = sys_get_temp_dir().'/cache-validator.php';
3232
@unlink($file);
@@ -46,7 +46,7 @@ public function testWarmUpWithAnnotations()
4646
{
4747
$validatorBuilder = new ValidatorBuilder();
4848
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/categories.yml');
49-
$validatorBuilder->enableAnnotationMapping(true)->addDefaultDoctrineAnnotationReader();
49+
$validatorBuilder->enableAnnotationMapping();
5050

5151
$file = sys_get_temp_dir().'/cache-validator-with-annotations.php';
5252
@unlink($file);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
8181
use Symfony\Component\Validator\Validation;
8282
use Symfony\Component\Validator\Validator\ValidatorInterface;
83+
use Symfony\Component\Validator\ValidatorBuilder;
8384
use Symfony\Component\Webhook\Client\RequestParser;
8485
use Symfony\Component\Webhook\Controller\WebhookController;
8586
use Symfony\Component\Workflow;

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Category.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class Category
1010

1111
public $id;
1212

13-
/**
14-
* @Assert\Type("string")
15-
*/
13+
#[Assert\Type('string')]
1614
public $name;
1715
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Symfony\Component\PropertyInfo\Tests\Extractor;
1313

14-
use Doctrine\Common\Annotations\AnnotationReader;
1514
use PHPUnit\Framework\TestCase;
1615
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
1716
use Symfony\Component\PropertyInfo\Tests\Fixtures\AdderRemoverDummy;
17+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
1818
use Symfony\Component\PropertyInfo\Tests\Fixtures\IgnorePropertyDummy;
1919
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
2020
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
@@ -24,22 +24,19 @@
2424
*/
2525
class SerializerExtractorTest extends TestCase
2626
{
27-
/**
28-
* @var SerializerExtractor
29-
*/
30-
private $extractor;
27+
private SerializerExtractor $extractor;
3128

3229
protected function setUp(): void
3330
{
34-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
31+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader());
3532
$this->extractor = new SerializerExtractor($classMetadataFactory);
3633
}
3734

3835
public function testGetProperties()
3936
{
4037
$this->assertEquals(
4138
['collection'],
42-
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', ['serializer_groups' => ['a']])
39+
$this->extractor->getProperties(Dummy::class, ['serializer_groups' => ['a']])
4340
);
4441
}
4542

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class Dummy extends ParentDummy
4242

4343
/**
4444
* @var \DateTimeImmutable[]
45-
* @Groups({"a", "b"})
4645
*/
46+
#[Groups(['a', 'b'])]
4747
public $collection;
4848

4949
/**

src/Symfony/Component/PropertyInfo/Tests/Fixtures/IgnorePropertyDummy.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@
1919
*/
2020
class IgnorePropertyDummy
2121
{
22-
/**
23-
* @Groups({"a"})
24-
*/
22+
#[Groups(['a'])]
2523
public $visibleProperty;
2624

27-
/**
28-
* @Groups({"a"})
29-
* @Ignore
30-
*/
25+
#[Groups(['a']), Ignore]
3126
private $ignoredProperty;
3227
}

src/Symfony/Component/PropertyInfo/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
"symfony/cache": "^6.4|^7.0",
3232
"symfony/dependency-injection": "^6.4|^7.0",
3333
"phpdocumentor/reflection-docblock": "^5.2",
34-
"phpstan/phpdoc-parser": "^1.0",
35-
"doctrine/annotations": "^1.10.4|^2"
34+
"phpstan/phpdoc-parser": "^1.0"
3635
},
3736
"conflict": {
3837
"phpdocumentor/reflection-docblock": "<5.2",
3938
"phpdocumentor/type-resolver": "<1.5.1",
40-
"symfony/dependency-injection": "<6.4"
39+
"symfony/dependency-injection": "<6.4",
40+
"symfony/serializer": "<6.4"
4141
},
4242
"autoload": {
4343
"psr-4": { "Symfony\\Component\\PropertyInfo\\": "" },

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ CHANGELOG
1313
* Require explicit argument when calling `AttributeMetadata::setSerializedName()` and `ClassMetadata::setClassDiscriminatorMapping()`
1414
* Add argument `$context` to `NormalizerInterface::supportsNormalization()` and `DenormalizerInterface::supportsDenormalization()`
1515

16+
6.4
17+
---
18+
19+
* Deprecate Doctrine annotations support in favor of native attributes
20+
* Deprecate passing an annotation reader to the constructor of `AnnotationLoader`
21+
1622
6.3
1723
---
1824

src/Symfony/Component/Serializer/Encoder/YamlEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
5353
public function __construct(Dumper $dumper = null, Parser $parser = null, array $defaultContext = [])
5454
{
5555
if (!class_exists(Dumper::class)) {
56-
throw new RuntimeException('The YamlEncoder class requires the "Yaml" component. Install "symfony/yaml" to use it.');
56+
throw new RuntimeException('The YamlEncoder class requires the "Yaml" component. Try running "composer require symfony/yaml".');
5757
}
5858

5959
if (!$dumper) {

src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class AnnotationLoader implements LoaderInterface
4646
public function __construct(
4747
private readonly ?Reader $reader = null,
4848
) {
49+
if ($reader) {
50+
trigger_deprecation('symfony/validator', '6.4', 'Passing a "%s" instance as argument 1 to "%s()" is deprecated, pass null or omit the parameter instead.', get_debug_type($reader), __METHOD__);
51+
}
4952
}
5053

5154
public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
@@ -163,10 +166,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
163166
return $loaded;
164167
}
165168

166-
/**
167-
* @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflector
168-
*/
169-
public function loadAnnotations(object $reflector): iterable
169+
public function loadAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $reflector): iterable
170170
{
171171
foreach ($reflector->getAttributes() as $attribute) {
172172
if ($this->isKnownAttribute($attribute->getName())) {
@@ -193,13 +193,13 @@ public function loadAnnotations(object $reflector): iterable
193193
}
194194

195195
if ($reflector instanceof \ReflectionClass) {
196-
yield from $this->reader->getClassAnnotations($reflector);
196+
yield from $this->getClassAnnotations($reflector);
197197
}
198198
if ($reflector instanceof \ReflectionMethod) {
199-
yield from $this->reader->getMethodAnnotations($reflector);
199+
yield from $this->getMethodAnnotations($reflector);
200200
}
201201
if ($reflector instanceof \ReflectionProperty) {
202-
yield from $this->reader->getPropertyAnnotations($reflector);
202+
yield from $this->getPropertyAnnotations($reflector);
203203
}
204204
}
205205

@@ -229,4 +229,49 @@ private function isKnownAttribute(string $attributeName): bool
229229

230230
return false;
231231
}
232+
233+
/**
234+
* @return object[]
235+
*/
236+
private function getClassAnnotations(\ReflectionClass $reflector): array
237+
{
238+
if ($annotations = array_filter(
239+
$this->reader->getClassAnnotations($reflector),
240+
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
241+
)) {
242+
trigger_deprecation('symfony/serializer', '6.4', 'Class "%s" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getName());
243+
}
244+
245+
return $annotations;
246+
}
247+
248+
/**
249+
* @return object[]
250+
*/
251+
private function getMethodAnnotations(\ReflectionMethod $reflector): array
252+
{
253+
if ($annotations = array_filter(
254+
$this->reader->getMethodAnnotations($reflector),
255+
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
256+
)) {
257+
trigger_deprecation('symfony/serializer', '6.4', 'Method "%s::%s()" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getDeclaringClass()->getName(), $reflector->getName());
258+
}
259+
260+
return $annotations;
261+
}
262+
263+
/**
264+
* @return object[]
265+
*/
266+
private function getPropertyAnnotations(\ReflectionProperty $reflector): array
267+
{
268+
if ($annotations = array_filter(
269+
$this->reader->getPropertyAnnotations($reflector),
270+
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
271+
)) {
272+
trigger_deprecation('symfony/serializer', '6.4', 'Property "%s::$%s" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getDeclaringClass()->getName(), $reflector->getName());
273+
}
274+
275+
return $annotations;
276+
}
232277
}

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class ObjectNormalizer extends AbstractObjectNormalizer
3838
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, ca F438 llable $objectClassResolver = null, array $defaultContext = [])
3939
{
4040
if (!class_exists(PropertyAccess::class)) {
41-
throw new LogicException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.');
41+
throw new LogicException('The ObjectNormalizer class requires the "PropertyAccess" component. Try running "composer require symfony/property-access".');
4242
}
4343

4444
parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor, $classDiscriminatorResolver, $objectClassResolver, $defaultContext);

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/GroupDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Serializer\Annotation\Groups;
1515
use Symfony\Component\Serializer\Tests\Fixtures\ChildOfGroupsAnnotationDummy;
16-
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyInterface;
16+
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummyInterface;
1717

1818
/**
1919
* @author Kévin Dunglas <dunglas@gmail.com>

src/Symfony/Component/Serializer/Tests/Fixtures/GroupDummyInterface.php renamed to src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/GroupDummyInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Fixtures;
12+
namespace Symfony\Component\Serializer\Tests\Fixtures\Annotations;
1313

1414
use Symfony\Component\Serializer\Annotation\Groups;
1515

src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/GroupDummy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Serializer\Annotation\Groups;
1515
use Symfony\Component\Serializer\Tests\Fixtures\ChildOfGroupsAnnotationDummy;
16-
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyInterface;
1716

1817
/**
1918
* @author Kévin Dunglas <dunglas@gmail.com>

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/GroupDummyChild.php renamed to src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/GroupDummyChild.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Fixtures\Annotations;
12+
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
1313

1414
class GroupDummyChild extends GroupDummy
1515
{

0 commit comments

Comments
 (0)
0