Skip to content

Commit 1ccc1c7

Browse files
committed
Add UserPassword and Valid
1 parent 8c8e1a9 commit 1ccc1c7

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

reference/constraints/UserPassword.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ the user's current password:
5151
protected $oldPassword;
5252
}
5353
54+
.. code-block:: php-attributes
55+
56+
// src/Form/Model/ChangePassword.php
57+
namespace App\Form\Model;
58+
59+
use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
60+
61+
class ChangePassword
62+
{
63+
#[SecurityAssert\UserPassword(
64+
message: 'Wrong value for your current password',
65+
)]
66+
protected $oldPassword;
67+
}
68+
5469
.. code-block:: yaml
5570
5671
# config/validator/validation.yaml

reference/constraints/Valid.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,40 @@ stores an ``Address`` instance in the ``$address`` property::
8787
protected $address;
8888
}
8989
90+
.. code-block:: php-attributes
91+
92+
// src/Entity/Address.php
93+
namespace App\Entity;
94+
95+
use Symfony\Component\Validator\Constraints as Assert;
96+
97+
class Address
98+
{
99+
#[Assert\NotBlank]
100+
protected $street;
101+
102+
#[Assert\NotBlank]
103+
#[Assert\Length(max: 5)]
104+
protected $zipCode;
105+
}
106+
107+
// src/Entity/Author.php
108+
namespace App\Entity;
109+
110+
use Symfony\Component\Validator\Constraints as Assert;
111+
112+
class Author
113+
{
114+
#[Assert\NotBlank]
115+
#[Assert\Length(min: 4)]
116+
protected $firstName;
117+
118+
#[Assert\NotBlank]
119+
protected $lastName;
120+
121+
protected $address;
122+
}
123+
90124
.. code-block:: yaml
91125
92126
# config/validator/validation.yaml
@@ -196,6 +230,19 @@ an invalid address. To prevent that, add the ``Valid`` constraint to the
196230
protected $address;
197231
}
198232
233+
.. code-block:: php-attributes
234+
235+
// src/Entity/Author.php
236+
namespace App\Entity;
237+
238+
use Symfony\Component\Validator\Constraints as Assert;
239+
240+
class Author
241+
{
242+
#[Assert\Valid]
243+
protected $address;
244+
}
245+
199246
.. code-block:: yaml
200247
201248
# config/validator/validation.yaml

0 commit comments

Comments
 (0)