Skip to content

[Validator] Allow Sequence constraint to be applied onto class as an attribute #44448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Validator] Allow Sequence constraint to be applied onto class as an …
…attribute
  • Loading branch information
sidz authored and nicolas-grekas committed Dec 15, 2021
commit 8c1e746a659c5fcdd193c1498bf62377290ce248
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Sequentially extends Composite
{
public $constraints = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* @Symfony\Component\Validator\Tests\Fixtures\ConstraintA
* @Assert\GroupSequence({"Foo", "Entity"})
* @Assert\Callback({"Symfony\Component\Validator\Tests\Fixtures\CallbackClass", "callback"})
* @Assert\Sequentially({
* @Assert\Expression("this.getFirstName() != null")
* })
*/
class Entity extends EntityParent implements EntityInterfaceB
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
Assert\GroupSequence(['Foo', 'Entity']),
Assert\Callback([CallbackClass::class, 'callback']),
]
/**
* @Assert\Sequentially({
* @Assert\Expression("this.getFirstName() != null")
* })
*/
class Entity extends EntityParent implements EntityInterfaceB
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
ConstraintA,
Assert\GroupSequence(['Foo', 'Entity']),
Assert\Callback([CallbackClass::class, 'callback']),
Assert\Sequentially([
new Assert\Expression('this.getFirstName() != null')
])
]
class Entity extends EntityParent implements EntityInterfaceB
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Expression;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
Expand Down Expand Up @@ -65,6 +66,9 @@ public function testLoadClassMetadata(string $namespace)
$expected->setGroupSequence(['Foo', 'Entity']);
$expected->addConstraint(new ConstraintA());
$expected->addConstraint(new Callback(['Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback']));
$expected->addConstraint(new Sequentially([
new Expression('this.getFirstName() != null'),
]));
$expected->addConstraint(new Callback(['callback' => 'validateMe', 'payload' => 'foo']));
$expected->addConstraint(new Callback('validateMeStatic'));
$expected->addPropertyConstraint('firstName', new NotNull());
Expand Down Expand Up @@ -151,6 +155,9 @@ public function testLoadClassMetadataAndMerge(string $namespace)
$expected->setGroupSequence(['Foo', 'Entity']);
$expected->addConstraint(new ConstraintA());
$expected->addConstraint(new Callback(['Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback']));
$expected->addConstraint(new Sequentially([
new Expression('this.getFirstName() != null'),
]));
$expected->addConstraint(new Callback(['callback' => 'validateMe', 'payload' => 'foo']));
$expected->addConstraint(new Callback('validateMeStatic'));
$expected->addPropertyConstraint('firstName', new NotNull());
Expand Down
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