Skip to content

Commit 085f281

Browse files
Merge branch '4.4' into 5.0
* 4.4: [Validator] Fix auto-mapping constraints should not be validated [Debug] Updated the README to deprecate the component [Cache] fix memory leak when using PhpFilesAdapter [Yaml] Implement multiline string as scalar block for tagged values [HttpFoundation] Use `Cache-Control: must-revalidate` only if explicit lifetime has been given [FrameworkBundle] Use UserInterface to @return in getUser method [CI] Replace php7.4snapshot with php7.4 in Travis configuration [ExpressionLanguage][Node][BinaryNode] Process division by zero Fixing bad order of operations with null coalescing operator forward caught exception [Validator][ConstraintValidator] Stop passing unnecessary timezone argument to \DateTime add tags before processing them [FrameworkBundle][ContainerLintCommand] Reinitialize bundles when the container is reprepared [Process] change the syntax of portable prepared command lines [MonologBridge] Fix debug processor datetime type
2 parents a9b385f + 464fda8 commit 085f281

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Tests/Validator/DoctrineLoaderTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderParentEntity;
2222
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
2323
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
24-
use Symfony\Component\Validator\Constraints\DisableAutoMapping;
2524
use Symfony\Component\Validator\Constraints\Length;
25+
use Symfony\Component\Validator\Mapping\AutoMappingStrategy;
2626
use Symfony\Component\Validator\Mapping\CascadingStrategy;
2727
use Symfony\Component\Validator\Mapping\ClassMetadata;
2828
use Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait;
29+
use Symfony\Component\Validator\Mapping\PropertyMetadata;
2930
use Symfony\Component\Validator\Mapping\TraversalStrategy;
3031
use Symfony\Component\Validator\Tests\Fixtures\Entity;
3132
use Symfony\Component\Validator\Validation;
@@ -140,11 +141,12 @@ public function testLoadClassMetadata()
140141
$this->assertInstanceOf(Length::class, $textFieldConstraints[0]);
141142
$this->assertSame(1000, $textFieldConstraints[0]->max);
142143

144+
/** @var PropertyMetadata[] $noAutoMappingMetadata */
143145
$noAutoMappingMetadata = $classMetadata->getPropertyMetadata('noAutoMapping');
144146
$this->assertCount(1, $noAutoMappingMetadata);
145147
$noAutoMappingConstraints = $noAutoMappingMetadata[0]->getConstraints();
146-
$this->assertCount(1, $noAutoMappingConstraints);
147-
$this->assertInstanceOf(DisableAutoMapping::class, $noAutoMappingConstraints[0]);
148+
$this->assertCount(0, $noAutoMappingConstraints);
149+
$this->assertSame(AutoMappingStrategy::DISABLED, $noAutoMappingMetadata[0]->getAutoMappingStrategy());
148150
}
149151

150152
public function testFieldMappingsConfiguration()
@@ -205,13 +207,15 @@ public function testClassNoAutoMapping()
205207
$classMetadata = $validator->getMetadataFor(new DoctrineLoaderNoAutoMappingEntity());
206208

207209
$classConstraints = $classMetadata->getConstraints();
208-
$this->assertCount(1, $classConstraints);
209-
$this->assertInstanceOf(DisableAutoMapping::class, $classConstraints[0]);
210+
$this->assertCount(0, $classConstraints);
211+
$this->assertSame(AutoMappingStrategy::DISABLED, $classMetadata->getAutoMappingStrategy());
210212

211213
$maxLengthMetadata = $classMetadata->getPropertyMetadata('maxLength');
212214
$this->assertEmpty($maxLengthMetadata);
213215

216+
/** @var PropertyMetadata[] $autoMappingExplicitlyEnabledMetadata */
214217
$autoMappingExplicitlyEnabledMetadata = $classMetadata->getPropertyMetadata('autoMappingExplicitlyEnabled');
215-
$this->assertCount(2, $autoMappingExplicitlyEnabledMetadata[0]->constraints);
218+
$this->assertCount(1, $autoMappingExplicitlyEnabledMetadata[0]->constraints);
219+
$this->assertSame(AutoMappingStrategy::ENABLED, $autoMappingExplicitlyEnabledMetadata[0]->getAutoMappingStrategy());
216220
}
217221
}

Validator/DoctrineLoader.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1717
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
1818
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
19-
use Symfony\Component\Validator\Constraints\DisableAutoMapping;
20-
use Symfony\Component\Validator\Constraints\EnableAutoMapping;
2119
use Symfony\Component\Validator\Constraints\Length;
2220
use Symfony\Component\Validator\Constraints\Valid;
21+
use Symfony\Component\Validator\Mapping\AutoMappingStrategy;
2322
use Symfony\Component\Validator\Mapping\ClassMetadata;
2423
use Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait;
2524
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
@@ -76,13 +75,16 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
7675
$enabledForProperty = $enabledForClass;
7776
$lengthConstraint = null;
7877
foreach ($metadata->getPropertyMetadata($mapping['fieldName']) as $propertyMetadata) {
78+
// Enabling or disabling auto-mapping explicitly always takes precedence
79+
if (AutoMappingStrategy::DISABLED === $propertyMetadata->getAutoMappingStrategy()) {
80+
continue 2;
81+
}
82+
if (AutoMappingStrategy::ENABLED === $propertyMetadata->getAutoMappingStrategy()) {
83+
$enabledForProperty = true;
84+
}
85+
7986
foreach ($propertyMetadata->getConstraints() as $constraint) {
80-
// Enabling or disabling auto-mapping explicitly always takes precedence
81-
if ($constraint instanceof DisableAutoMapping) {
82-
continue 3;
83-
} elseif ($constraint instanceof EnableAutoMapping) {
84-
$enabledForProperty = true;
85-
} elseif ($constraint instanceof Length) {
87+
if ($constraint instanceof Length) {
8688
$lengthConstraint = $constraint;
8789
}
8890
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"symfony/proxy-manager-bridge": "^4.4|^5.0",
3636
"symfony/security-core": "^5.0",
3737
"symfony/expression-language": "^4.4|^5.0",
38-
"symfony/validator": "^5.0",
38+
"symfony/validator": "^5.0.1",
3939
"symfony/translation": "^4.4|^5.0",
4040
"symfony/var-dumper": "^4.4|^5.0",
4141
"doctrine/annotations": "~1.7",
@@ -55,7 +55,7 @@
5555
"symfony/property-info": "<5",
5656
"symfony/security-bundle": "<5",
5757
"symfony/security-core": "<5",
58-
"symfony/validator": "<5"
58+
"symfony/validator": "<5.0.1"
5959
},
6060
"suggest": {
6161
"symfony/form": "",

0 commit comments

Comments
 (0)