8000 Merge branch '3.4' into 4.2 · symfony/symfony-docs@b14c33c · GitHub
[go: up one dir, main page]

Skip to content

Commit b14c33c

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: streamline the constraints reference
2 parents cbf32ab + 41fa05e commit b14c33c

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
@@ -36,7 +36,7 @@ entry in that array:
3636
* @Assert\Length(min=5)
3737
* })
3838
*/
39-
protected $favoriteColors = [];
39+
protected $favoriteColors = [];
4040
}
4141
4242
.. code-block:: yaml

reference/constraints/Bic.rst

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

reference/constraints/Callback.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ Configuration
8484
{
8585
$metadata->addConstraint(new Assert\Callback('validate'));
8686
}
87+
88+
public function validate(ExecutionContextInterface $context, $payload)
89+
{
90+
// ...
91+
}
8792
}
8893
8994
The Callback Method

reference/constraints/CardScheme.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ on an object that will contain a credit card number.
8181
8282
class Transaction
8383
{
84-
protected $cardNumber;
85-
8684
public static function loadValidatorMetadata(ClassMetadata $metadata)
8785
{
8886
$metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme([

reference/constraints/Choice.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ If your valid choice list is simple, you can pass them in directly via the
108108
109109
class Author
110110
{
111-
protected $genre;
112-
113111
public static function loadValidatorMetadata(ClassMetadata $metadata)
114112
{
115113
$metadata->addPropertyConstraint(

reference/constraints/Collection.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ following:
138138
139139
class Author
140140
{
141-
private $options = [];
142-
143141
public static function loadValidatorMetadata(ClassMetadata $metadata)
144142
{
145143
$metadata->addPropertyConstraint('profileData', new Assert\Collection([
@@ -205,7 +203,7 @@ you can do the following:
205203
* }
206204
* )
207205
*/
208-
protected $profileData = ['personal_email'];
206+
protected $profileData = ['personal_email'];
209207
}
210208
211209
.. code-block:: yaml
@@ -269,9 +267,10 @@ you can do the following:
269267
{
270268
$metadata->addPropertyConstraint('profileData', new Assert\Collection([
271269
'fields' => [
272-
'personal_email' => new Assert\Required(
273-
[new Assert\NotBlank(), new Assert\Email()]
274-
),
270+
'personal_email' => new Assert\Required([
271+
new Assert\NotBlank(),
272+
new Assert\Email(),
273+
]),
275274
'alternate_email' => new Assert\Optional(new Assert\Email()),
276275
],
277276
]));

reference/constraints/Count.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ you might add the following:
4242
* maxMessage = "You cannot specify more than {{ limit }} emails"
4343
* )
4444
*/
45-
protected $emails = [];
45+
protected $emails = [];
4646
}
4747
4848
.. code-block:: yaml
@@ -90,8 +90,8 @@ you might add the following:
9090
public static function loadValidatorMetadata(ClassMetadata $metadata)
9191
{
9292
$metadata->addPropertyConstraint('emails', new Assert\Count([
93-
'min' => 1,
94-
'max' => 5,
93+
'min' => 1,
94+
'max' => 5,
9595
'minMessage' => 'You must specify at least one email',
9696
'maxMessage' => 'You cannot specify more than {{ limit }} emails',
9797
]));

reference/constraints/Country.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Basic Usage
2929
/**
3030
* @Assert\Country
3131
*/
32-
protected $country;
32+
protected $country;
3333
}
3434
3535
.. code-block:: yaml

reference/constraints/Date.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Basic Usage
3131
* @Assert\Date
3232
* @var string A "Y-m-d" formatted value
3333
*/
34-
protected $birthday;
34+
protected $birthday;
3535
}
3636
3737
.. code-block:: yaml

reference/constraints/DateTime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Basic Usage
3232
* @Assert\DateTime
3333
* @var string A "Y-m-d H:i:s" formatted value
3434
*/
35-
protected $createdAt;
35+
protected $createdAt;
3636
}
3737
3838
.. code-block:: yaml

reference/constraints/Email.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Basic Usage
3636
* checkMX = true
3737
* )
3838
*/
39-
protected $email;
39+
protected $email;
4040
}
4141
4242
.. code-block:: yaml

reference/constraints/Image.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,11 @@ following code:
212212
213213
class Author
214214
{
215-
// ...
216-
217215
public static function loadValidatorMetadata(ClassMetadata $metadata)
218216
{
219217
$metadata->addPropertyConstraint('headshot', new Assert\Image([
220-
'allowLandscape' => false,
221-
'allowPortrait' => false,
218+
'allowLandscape' => false,
219+
'allowPortrait' => false,
222220
]));
223221
}
224222
}

reference/constraints/Ip.rst

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

reference/constraints/IsFalse.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ method returns **false**:
5252
* message = "You've entered an invalid state."
5353
* )
5454
*/
55-
public function isStateInvalid()
56-
{
55+
public function isStateInvalid()
56+
{
5757
// ...
58-
}
58+
}
5959
}
6060
6161
.. code-block:: yaml
@@ -96,10 +96,17 @@ method returns **false**:
9696
{
9797
public static function loadValidatorMetadata(ClassMetadata $metadata)
9898
{
99-
$metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse());
99+
$metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse([
100+
'message' => 'You've entered an invalid state.',
101+
]));
100102
}
101103
}
102104
105+
public function isStateInvalid()
106+
{
107+
// ...
108+
}
109+
103110
Options
104111
-------
105112

reference/constraints/IsTrue.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Then you can constrain this method with ``IsTrue``.
5353
protected $token;
5454
5555
/**
56-
* @Assert\IsTrue(message="The token is invalid")
56+
* @Assert\IsTrue(message="The token is invalid.")
5757
*/
5858
public function isTokenValid()
5959
{
@@ -97,8 +97,6 @@ Then you can constrain this method with ``IsTrue``.
9797
9898
class Author
9999
{
100-
protected $token;
101-
102100
public static function loadValidatorMetadata(ClassMetadata $metadata)
103101
{
104102
$metadata->addGetterConstraint('tokenValid', new IsTrue([

reference/constraints/Isbn.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ on an object that will contain an ISBN.
8181
8282
class Book
8383
{
84-
protected $isbn;
85-
8684
public static function loadValidatorMetadata(ClassMetadata $metadata)
8785
{
8886
$metadata->addPropertyConstraint('isbn', new Assert\Isbn([
89-
'type' => 'isbn10',
87+
'type' => 'isbn10',
9088
'message' => 'This value is not valid.',
9189
]));
9290
}

reference/constraints/Issn.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Basic Usage
3232
/**
3333
* @Assert\Issn
3434
*/
35-
protected $issn;
35+
protected $issn;
3636
}
3737
3838
.. code-block:: yaml
@@ -92,7 +92,7 @@ When switching this to ``true``, the validator requires an upper case 'X'.
9292
message
9393
~~~~~~~
9494

95-
**type**: ``String`` default: ``This value is not a valid ISSN.``
95+
**type**: ``string`` default: ``This value is not a valid ISSN.``
9696

9797
The message shown if the given value is not a valid ISSN.
9898

reference/constraints/Language.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Basic Usage
3030
/**
3131
* @Assert\Language
3232
*/
33-
protected $preferredLanguage;
33+
protected $preferredLanguage;
3434
}
3535
3636
.. code-block:: yaml

reference/constraints/Length.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ and "50", you might add the following:
4949
* maxMessage = "Your first name cannot be longer than {{ limit }} characters"
5050
* )
5151
*/
52-
protected $firstName;
52+
protected $firstName;
5353
}
5454
5555
.. code-block:: yaml
@@ -101,8 +101,8 @@ and "50", you might add the following:
101101
public static function loadValidatorMetadata(ClassMetadata $metadata)
102102
{
103103
$metadata->addPropertyConstraint('firstName', new Assert\Length([
104-
'min' => 2,
105-
'max' => 50,
104+
'min' => 2,
105+
'max' => 50,
106106
'minMessage' => 'Your first name must be at least {{ limit }} characters long',
107107
'maxMessage' => 'Your first name cannot be longer than {{ limit }} characters',
108108
]));

reference/constraints/Locale.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Basic Usage
3737
* canonicalize = true
3838
* )
3939
*/
40-
protected $locale;
40+
protected $locale;
4141
}
4242
4343
.. code-block:: yaml

reference/constraints/Range.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ you might add the following:
8989
public static function loadValidatorMetadata(ClassMetadata $metadata)
9090
{
9191
$metadata->addPropertyConstraint('height', new Assert\Range([
92-
'min' => 120,
93-
'max' => 180,
92+
'min' => 120,
93+
'max' => 180,
9494
'minMessage' => 'You must be at least {{ limit }}cm tall to enter',
9595
'maxMessage' => 'You cannot be taller than {{ limit }}cm to enter',
9696
]));

reference/constraints/Regex.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ it a custom message:
153153
{
154154
$metadata->addPropertyConstraint('firstName', new Assert\Regex([
155155
'pattern' => '/\d/',
156-
'match' => false,
156+
'match' => false,
157157
'message' => 'Your name cannot contain a number',
158158
]));
159159
}
@@ -243,7 +243,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
243243
public static function loadValidatorMetadata(ClassMetadata $metadata)
244244
{
245245
$metadata->addPropertyConstraint('name', new Assert\Regex([
246-
'pattern' => '/^[a-z]+$/i',
246+
'pattern' => '/^[a-z]+$/i',
247247
'htmlPattern' => '^[a-zA-Z]+$',
248248
]));
249249
}

reference/constraints/Time.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ of the day when the event starts:
3434
* @Assert\Time
3535
* @var string A "H:i:s" formatted value
3636
*/
37-
protected $startsAt;
37+
protected $startsAt;
3838
}
3939
4040
.. code-block:: yaml

reference/constraints/Type.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an
9797
$metadata->addPropertyConstraint('firstName', new Assert\Type('string'));
9898
9999
$metadata->addPropertyConstraint('age', new Assert\Type([
100-
'type' => 'integer',
100+
'type' => 'integer',
101101
'message' => 'The value {{ value }} is not a valid {{ type }}.',
102102
]));
103103
}

reference/constraints/UniqueEntity.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ between all of the constraints in your user table:
4747
class Author
4848
{
4949
/**
50-
* @var string $email
51-
*
5250
* @ORM\Column(name="email", type="string", length=255, unique=true)
5351
* @Assert\Email
5452
*/
5553
protected $email;
56-
57-
// ...
5854
}
5955
6056
.. code-block:: yaml
@@ -100,7 +96,7 @@ between all of the constraints in your user table:
10096
public static function loadValidatorMetadata(ClassMetadata $metadata)
10197
{
10298
$metadata->addConstraint(new UniqueEntity([
103-
'fields' => 'email',
99+
'fields' => 'email',
104100
]));
105101
106102
$metadata->addPropertyConstraint('email', new Assert\Email());
@@ -227,9 +223,9 @@ Consider this example:
227223
public static function loadValidatorMetadata(ClassMetadata $metadata)
228224
{
229225
$metadata->addConstraint(new UniqueEntity([
230-
'fields' => ['host', 'port'],
226+
'fields' => ['host', 'port'],
231227
'errorPath' => 'port',
232-
'message' => 'This port is already in use on that host.',
228+
'message' => 'This port is already in use on that host.',
233229
]));
234230
}
235231
}

0 commit comments

Comments
 (0)
0