Skip to content

Commit 8f591c3

Browse files
bug #44448 [Validator] Allow Sequence constraint to be applied onto class as an attribute (sidz)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Validator] Allow Sequence constraint to be applied onto class as an attribute | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #44531 | License | MIT | Doc PR | N/A This PR allows to apply `Sequentially` constraint as an attribute onto class target. Looks like it was missed on translating annotations to attributes. ![image](https://user-images.githubusercontent.com/1302230/144623891-98bde6b2-2376-4ac0-93fc-58b43a0b0f94.png) ![image](https://user-images.githubusercontent.com/1302230/144623958-7d5fe384-771a-4711-8c28-0e9bddfc4c41.png) Commits ------- 8c1e746 [Validator] Allow Sequence constraint to be applied onto class as an attribute
2 parents d5d0cec + 8c1e746 commit 8f591c3

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
2222
*/
23-
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
23+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
2424
class Sequentially extends Composite
2525
{
2626
public $constraints = [];

src/Symfony/Component/Validator/Tests/Fixtures/Annotation/Entity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* @Symfony\Component\Validator\Tests\Fixtures\ConstraintA
2020
* @Assert\GroupSequence({"Foo", "Entity"})
2121
* @Assert\Callback({"Symfony\Component\Validator\Tests\Fixtures\CallbackClass", "callback"})
22+
* @Assert\Sequentially({
23+
* @Assert\Expression("this.getFirstName() != null")
24+
* })
2225
*/
2326
class Entity extends EntityParent implements EntityInterfaceB
2427
{

src/Symfony/Component/Validator/Tests/Fixtures/Attribute/Entity.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
Assert\GroupSequence(['Foo', 'Entity']),
2323
Assert\Callback([CallbackClass::class, 'callback']),
2424
]
25+
/**
26+
* @Assert\Sequentially({
27+
* @Assert\Expression("this.getFirstName() != null")
28+
* })
29+
*/
2530
class Entity extends EntityParent implements EntityInterfaceB
2631
{
2732
/**

src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
ConstraintA,
2323
Assert\GroupSequence(['Foo', 'Entity']),
2424
Assert\Callback([CallbackClass::class, 'callback']),
25+
Assert\Sequentially([
26+
new Assert\Expression('this.getFirstName() != null')
27+
])
2528
]
2629
class Entity extends EntityParent implements EntityInterfaceB
2730
{

src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Validator\Constraints\Choice;
2020
use Symfony\Component\Validator\Constraints\Collection;
2121
use Symfony\Component\Validator\Constraints\Email;
22+
use Symfony\Component\Validator\Constraints\Expression;
2223
use Symfony\Component\Validator\Constraints\IsTrue;
2324
use Symfony\Component\Validator\Constraints\NotBlank;
2425
use Symfony\Component\Validator\Constraints\NotNull;
@@ -65,6 +66,9 @@ public function testLoadClassMetadata(string $namespace)
6566
$expected->setGroupSequence(['Foo', 'Entity']);
6667
$expected->addConstraint(new ConstraintA());
6768
$expected->addConstraint(new Callback(['Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback']));
69+
$expected->addConstraint(new Sequentially([
70+
new Expression('this.getFirstName() != null'),
71+
]));
6872
$expected->addConstraint(new Callback(['callback' => 'validateMe', 'payload' => 'foo']));
6973
$expected->addConstraint(new Callback('validateMeStatic'));
7074
$expected->addPropertyConstraint('firstName', new NotNull());
@@ -151,6 +155,9 @@ public function testLoadClassMetadataAndMerge(string $namespace)
151155
$expected->setGroupSequence(['Foo', 'Entity']);
152156
$expected->addConstraint(new ConstraintA());
153157
$expected->addConstraint(new Callback(['Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback']));
158+
$expected->addConstraint(new Sequentially([
159+
new Expression('this.getFirstName() != null'),
160+
]));
154161
$expected->addConstraint(new Callback(['callback' => 'validateMe', 'payload' => 'foo']));
155162
$expected->addConstraint(new Callback('validateMeStatic'));
156163
$expected->addPropertyConstraint('firstName', new NotNull());

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