Skip to content

Commit 9569ddd

Browse files
[FrameworkBundle][Validator] Remove remaining deprecations
1 parent ca6a07d commit 9569ddd

File tree

18 files changed

+101
-190
lines changed

18 files changed

+101
-190
lines changed

UPGRADE-7.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ FrameworkBundle
210210
* Make the `framework.uid.default_uuid_version` config option default to `7`
211211
* Make the `framework.uid.time_based_uuid_version` config option default to `7`
212212
* Make the `framework.validation.email_validation_mode` config option default to `html5`
213+
* Remove the `framework.validation.enable_annotations` config option, use `framework.validation.enable_attributes` instead
214+
* Remove the `framework.serializer.enable_annotations` config option, use `framework.serializer.enable_attributes` instead
213215

214216
HttpFoundation
215217
--------------
@@ -475,6 +477,9 @@ Validator
475477
* Remove the annotation reader parameter from the constructor signature of `AnnotationLoader`
476478
* Remove `ValidatorBuilder::setDoctrineAnnotationReader()`
477479
* Remove `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`
480+
* Remove `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead
481+
* Remove `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead
482+
* Remove `AnnotationLoader`, use `AttributeLoader` instead
478483

479484
VarDumper
480485
---------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ CHANGELOG
2222
* Make the `framework.uid.default_uuid_version` config option default to `7`
2323
* Make the `framework.uid.time_based_uuid_version` config option default to `7`
2424
* Make the `framework.validation.email_validation_mode` config option default to `html5`
25+
* Remove the `framework.validation.enable_annotations` config option, use `framework.validation.enable_attributes` instead
26+
* Remove the `framework.serializer.enable_annotations` config option, use `framework.serializer.enable_attributes` instead
2527

2628
6.4
2729
---

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,6 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
989989
->{$enableIfStandalone('symfony/validator', Validation::class)}()
990990
->children()
991991
->scalarNode('cache')->end()
992-
->booleanNode('enable_annotations')->end()
993992
->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
994993
->arrayNode('static_method')
995994
->defaultValue(['loadValidatorMetadata'])
@@ -1090,24 +1089,9 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
10901089
$rootNode
10911090
->children()
10921091
->arrayNode('serializer')
1093-
->validate()
1094-
->always(function ($v) {
1095-
if (isset($v['enable_annotations'])) {
1096-
trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.serializer" is deprecated. Use the "enable_attributes" option instead.');
1097-
1098-
if (!isset($v['enable_attributes'])) {
1099-
$v['enable_attributes'] = $v['enable_annotations'];
1100-
} else {
1101-
throw new LogicException('The "enable_annotations" and "enable_attributes" options at path "framework.serializer" must not be both set. Only the "enable_attributes" option must be used.');
1102-
}
1103-
}
1104-
1105-
return $v;
1106-
})->end()
11071092
->info('serializer configuration')
11081093
->{$enableIfStandalone('symfony/serializer', Serializer::class)}()
11091094
->children()
1110-
->booleanNode('enable_annotations')->end()
11111095
->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
11121096
->scalarNode('name_converter')->end()
11131097
->scalarNode('circular_reference_handler')->end()

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@
266266

267267
<xsd:attribute name="enabled" type="xsd:boolean" />
268268
<xsd:attribute name="cache" type="xsd:string" />
269-
<xsd:attribute name="enable-annotations" type="xsd:boolean" />
270269
<xsd:attribute name="enable-attributes" type="xsd:boolean" />
271270
<xsd:attribute name="static-method" type="xsd:boolean" />
272271
<xsd:attribute name="translation-domain" type="xsd:string" />
@@ -320,7 +319,6 @@
320319
<xsd:element name="default-context" type="metadata" minOccurs="0" maxOccurs="1" />
321320
</xsd:choice>
322321
<xsd:attribute name="enabled" type="xsd:boolean" />
323-
<xsd:attribute name="enable-annotations" type="xsd:boolean" />
324322
<xsd:attribute name="enable-attributes" type="xsd:boolean" />
325323
<xsd:attribute name="name-converter" type="xsd:string" />
326324
<xsd:attribute name="circular-reference-handler" type="xsd:string" />

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testDenormalizeWithNestedAttributesWithoutMetadata()
142142

143143
public function testDenormalizeWithSnakeCaseNestedAttributes()
144144
{
145-
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
145+
$factory = new ClassMetadataFactory(new AnnotationLoader());
146146
$normalizer = new ObjectNormalizer($factory, new CamelCaseToSnakeCaseNameConverter());
147147
$data = [
148148
'one' => [
@@ -155,7 +155,7 @@ public function testDenormalizeWithSnakeCaseNestedAttributes()
155155

156156
public function testNormalizeWithSnakeCaseNestedAttributes()
157157
{
158-
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
158+
$factory = new ClassMetadataFactory(new AnnotationLoader());
159159
$normalizer = new ObjectNormalizer($factory, new CamelCaseToSnakeCaseNameConverter());
160160
$dummy = new SnakeCaseNestedDummy();
161161
$dummy->fooBar = 'fooBar';
@@ -866,9 +866,7 @@ public function __construct(
866866

867867
class SnakeCaseNestedDummy
868868
{
869-
/**
870-
* @SerializedPath("[one][two_three]")
871-
*/
869+
#[SerializedPath('[one][two_three]')]
872870
public $fooBar;
873871
}
874872

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ CHANGELOG
1515
* Remove the annotation reader parameter from the constructor signature of `AnnotationLoader`
1616
* Remove `ValidatorBuilder::setDoctrineAnnotationReader()`
1717
* Remove `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`
18+
* Remove `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead
19+
* Remove `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead
20+
* Remove `AnnotationLoader`, use `AttributeLoader` instead
1821

1922
6.4
2023
---

src/Symfony/Component/Validator/Constraints/Callback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Callback extends Constraint
2626

2727
public function __construct(array|string|callable $callback = null, array $groups = null, mixed $payload = null, array $options = [])
2828
{
29-
// Invocation through annotations with an array parameter only
29+
// Invocation through attributes with an array parameter only
3030
if (\is_array($callback) && 1 === \count($callback) && isset($callback['value'])) {
3131
$callback = $callback['value'];
3232
}

src/Symfony/Component/Validator/Constraints/When.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
use Symfony\Component\Validator\Constraint;
1717
use Symfony\Component\Validator\Exception\LogicException;
1818

19-
/**
20-
* @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"})
21-
*/
2219
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
2320
class When extends Composite
2421
{

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

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,85 @@
1111

1212
namespace Symfony\Component\Validator\Mapping\Loader;
1313

14+
use Symfony\Component\Validator\Constraint;
15+
use Symfony\Component\Validator\Constraints\Callback;
16+
use Symfony\Component\Validator\Constraints\GroupSequence;
17+
use Symfony\Component\Validator\Constraints\GroupSequenceProvider;
18+
use Symfony\Component\Validator\Exception\MappingException;
19+
use Symfony\Component\Validator\Mapping\ClassMetadata;
20+
1421
/**
1522
* Loads validation metadata using PHP attributes.
1623
*
1724
* @author Bernhard Schussek <bschussek@gmail.com>
1825
* @author Alexander M. Turek <me@derrabus.de>
1926
* @author Alexandre Daubois <alex.daubois@gmail.com>
2027
*/
21-
class AttributeLoader extends AnnotationLoader
28+
class AttributeLoader implements LoaderInterface
2229
{
23-
public function __construct()
30+
public function loadClassMetadata(ClassMetadata $metadata): bool
31+
{
32+
$reflClass = $metadata->getReflectionClass();
33+
$className = $reflClass->name;
34+
$success = false;
35+
36+
foreach ($this->getAttributes($reflClass) as $constraint) {
37+
if ($constraint instanceof GroupSequence) {
38+
$metadata->setGroupSequence($constraint->groups);
39+
} elseif ($constraint instanceof GroupSequenceProvider) {
40+
$metadata->setGroupSequenceProvider(true);
41+
} elseif ($constraint instanceof Constraint) {
42+
$metadata->addConstraint($constraint);
43+
}
44+
45+
$success = true;
46+
}
47+
48+
foreach ($reflClass->getProperties() as $property) {
49+
if ($property->getDeclaringClass()->name === $className) {
50+
foreach ($this->getAttributes($property) as $constraint) {
51+
if ($constraint instanceof Constraint) {
52+
$metadata->addPropertyConstraint($property->name, $constraint);
53+
}
54+
55+
$success = true;
56+
}
57+
}
58+
}
59+
60+
foreach ($reflClass->getMethods() as $method) {
61+
if ($method->getDeclaringClass()->name === $className) {
62+
foreach ($this->getAttributes($method) as $constraint) {
63+
if ($constraint instanceof Callback) {
64+
$constraint->callback = $method->getName();
65+
66+
$metadata->addConstraint($constraint);
67+
} elseif ($constraint instanceof Constraint) {
68+
if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) {
69+
$metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint);
70+
} else {
71+
throw new MappingException(sprintf('The constraint on "%s::%s()" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name));
72+
}
73+
}
74+
75+
$success = true;
76+
}
77+
}
78+
}
79+
80+
return $success;
81+
}
82+
83+
private function getAttributes(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $reflection): iterable
2484
{
25-
parent::__construct(null);
85+
foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) {
86+
yield $attribute->newInstance();
87+
}
88+
foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) {
89+
yield $attribute->newInstance();
90+
}
91+
foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
92+
yield $attribute->newInstance();
93+
}
2694
}
2795
}

0 commit comments

Comments
 (0)
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