Skip to content

Commit 41fa05e

Browse files
committed
minor #11366 streamline the constraints reference (OskarStark)
This PR was merged into the 3.4 branch. Discussion ---------- streamline the constraints reference I felt the constraints need some love 💟 Commits ------- ce77fdb streamline the constraints reference
2 parents 7aafce9 + ce77fdb commit 41fa05e

29 files changed

+57
-71
lines changed

reference/constraints/All.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ entry in that array:
3939
* @Assert\Length(min=5)
4040
* })
4141
*/
42-
protected $favoriteColors = [];
42+
protected $favoriteColors = [];
4343
}
4444
4545
.. code-block:: yaml

reference/constraints/Bic.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ will contain a Business Identifier Code (BIC).
7373
7474
class Transaction
7575
{
76-
protected $businessIdentifierCode;
77-
7876
public static function loadValidatorMetadata(ClassMetadata $metadata)
7977
{
8078
$metadata->addPropertyConstraint('businessIdentifierCode', new Assert\Bic());

reference/constraints/Callback.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Configuration
8787
{
8888
$metadata->addConstraint(new Assert\Callback('validate'));
8989
}
90+
91+
public function validate(ExecutionContextInterface $context, $payload)
92+
{
93+
// ...
94+
}
9095
}
9196
9297
The Callback Method

reference/constraints/CardScheme.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ on an object that will contain a credit card number.
8484
8585
class Transaction
8686
{
87-
protected $cardNumber;
88-
8987
public static function loadValidatorMetadata(ClassMetadata $metadata)
9088
{
9189
$metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme([

reference/constraints/Choice.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ If your valid choice list is simple, you can pass them in directly via the
112112
113113
class Author
114114
{
115-
protected $genre;
116-
117115
public static function loadValidatorMetadata(ClassMetadata $metadata)
118116
{
119117
$metadata->addPropertyConstraint(

reference/constraints/Collection.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ following:
141141
142142
class Author
143143
{
144-
private $options = [];
145-
146144
public static function loadValidatorMetadata(ClassMetadata $metadata)
147145
{
148146
$metadata->addPropertyConstraint('profileData', new Assert\Collection([
@@ -208,7 +206,7 @@ you can do the following:
208206
* }
209207
* )
210208
*/
211-
protected $profileData = ['personal_email'];
209+
protected $profileData = ['personal_email'];
212210
}
213211
214212
.. code-block:: yaml
@@ -272,9 +270,10 @@ you can do the following:
272270
{
273271
$metadata->addPropertyConstraint('profileData', new Assert\Collection([
274272
'fields' => [
275-
'personal_email' => new Assert\Required(
276-
[new Assert\NotBlank(), new Assert\Email()]
277-
),
273+
'personal_email' => new Assert\Required([
274+
new Assert\NotBlank(),
275+
new Assert\Email(),
276+
]),
278277
'alternate_email' => new Assert\Optional(new Assert\Email()),
279278
],
280279
]));

reference/constraints/Count.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ you might add the following:
4545
* maxMessage = "You cannot specify more than {{ limit }} emails"
4646
* )
4747
*/
48-
protected $emails = [];
48+
protected $emails = [];
4949
}
5050
5151
.. code-block:: yaml
@@ -93,8 +93,8 @@ you might add the following:
9393
public static function loadValidatorMetadata(ClassMetadata $metadata)
9494
{
9595
$metadata->addPropertyConstraint('emails', new Assert\Count([
96-
'min' => 1,
97-
'max' => 5,
96+
'min' => 1,
97+
'max' => 5,
9898
'minMessage' => 'You must specify at least one email',
9999
'maxMessage' => 'You cannot specify more than {{ limit }} emails',
100100
]));

reference/constraints/Country.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Basic Usage
3232
/**
3333
* @Assert\Country
3434
*/
35-
protected $country;
35+
protected $country;
3636
}
3737
3838
.. code-block:: yaml

reference/constraints/Date.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Basic Usage
3434
/**
3535
* @Assert\Date
3636
*/
37-
protected $birthday;
37+
protected $birthday;
3838
}
3939
4040
.. code-block:: yaml

reference/constraints/DateTime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Basic Usage
3535
/**
3636
* @Assert\DateTime
3737
*/
38-
protected $createdAt;
38+
protected $createdAt;
3939
}
4040
4141
.. code-block:: yaml

0 commit comments

Comments
 (0)