Skip to content

Commit 0d13b84

Browse files
committed
[Validator] Allow Sequence constraint to be applied onto class as an attribute
1 parent 481cb9e commit 0d13b84

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Add a `CssColor` constraint to validate CSS colors
99
* Add support for `ConstraintViolationList::createFromMessage()`
1010
* Add error's uid to `Count` and `Length` constraints with "exactly" option enabled
11+
* Allow `Sequence` constraint to be applied onto class as an attribute
1112

1213
5.3
1314
---

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/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)