Skip to content

Commit ac44303

Browse files
committed
Added missing xml configuration examples for validation constraints
1 parent 2c2d4ff commit ac44303

File tree

17 files changed

+184
-8
lines changed

17 files changed

+184
-8
lines changed

reference/constraints/All.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ entry in that array:
5151
protected $favoriteColors = array();
5252
}
5353
54+
.. code-block:: xml
55+
56+
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
57+
<class name="Acme\UserBundle\Entity\User">
58+
<property name="favoriteColors">
59+
<constraint name="All">
60+
<option name="constraints">
61+
<constraint name="NotBlank" />
62+
<constraint name="Length">
63+
<option name="min">5</option>
64+
</constraint>
65+
</option>
66+
</constraint>
67+
</property>
68+
</class>
69+
5470
Now, each entry in the ``favoriteColors`` array will be validated to not
5571
be blank and to be at least 5 characters long.
5672

reference/constraints/Choice.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ If your valid choice list is simple, you can pass them in directly via the
4949
.. code-block:: xml
5050
5151
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
52-
<class name="Acme\BlogBundle\EntityAuthor">
52+
<class name="Acme\BlogBundle\Entity\Author">
5353
<property name="gender">
5454
<constraint name="Choice">
5555
<option name="choices">
@@ -280,4 +280,4 @@ strict
280280

281281
If true, the validator will also check the type of the input value. Specifically,
282282
this value is passed to as the third argument to the PHP :phpfunction:`in_array` method
283-
when checking to see if a value is in the valid choices array.
283+
when checking to see if a value is in the valid choices array.

reference/constraints/Count.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ you might add the following:
3838
- Count:
3939
min: 1
4040
max: 5
41-
minMessage: You must specify at least one email
42-
maxMessage: You cannot specify more than 5 emails
41+
minMessage: "You must specify at least one email"
42+
maxMessage: "You cannot specify more than {{ limit }} emails"
4343
4444
.. code-block:: php-annotations
4545
@@ -53,12 +53,27 @@ you might add the following:
5353
* min = "1",
5454
* max = "5",
5555
* minMessage = "You must specify at least one email",
56-
* maxMessage = "You cannot specify more than 5 emails"
56+
* maxMessage = "You cannot specify more than {{ limit }} emails"
5757
* )
5858
*/
5959
protected $emails = array();
6060
}
6161
62+
.. code-block:: xml
63+
64+
<!-- src/Acme/EventBundle/Resources/config/validation.xml -->
65+
<class name="Acme\EventBundle\Entity\Participant">
66+
<property name="emails">
67+
<constraint name="Count">
68+
<option name="min">1</option>
69+
<option name="max">5</option>
70+
<option name="minMessage">You must specify at least one email</option>
71+
<option name="maxMessage">You cannot specify more than {{ limit }} emails</option>
72+
</constraint>
73+
</property>
74+
</class>
75+
76+
6277
Options
6378
-------
6479

reference/constraints/Country.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ Basic Usage
4141
protected $country;
4242
}
4343
44+
.. code-block:: xml
45+
46+
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
47+
<class name="Acme\UserBundle\Entity\User">
48+
<property name="country">
49+
<constraint name="Country" />
50+
</property>
51+
</class>
52+
4453
Options
4554
-------
4655

reference/constraints/Date.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ Basic Usage
4141
protected $birthday;
4242
}
4343
44+
.. code-block:: xml
45+
46+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
47+
<class name="Acme\BlogBundle\Entity\Author">
48+
<property name="birthday">
49+
<constraint name="Date" />
50+
</property>
51+
</class>
52+
4453
Options
4554
-------
4655

reference/constraints/DateTime.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ Basic Usage
4343
protected $createdAt;
4444
}
4545
46+
.. code-block:: xml
47+
48+
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
49+
<class name="Acme\BlogBundle\Entity\Author">
50+
<property name="createdAt">
51+
<constraint name="DateTime" />
52+
</property>
53+
</class>
54+
4655
Options
4756
-------
4857

reference/constraints/False.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ method returns **false**:
4848
- "False":
4949
message: You've entered an invalid state.
5050
51+
.. code-block:: xml
52+
53+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
54+
<class name="Acme\BlogBundle\Entity\Author">
55+
<getter property="stateInvalid">
56+
<constraint name="False">
57+
<option name="message">You've entered an invalid state.</option>
58+
</constraint>
59+
</getter>
60+
</class>
61+
5162
.. code-block:: php-annotations
5263
5364
// src/Acme/BlogBundle/Entity/Author.php

reference/constraints/Ip.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ Basic Usage
4444
protected $ipAddress;
4545
}
4646
47+
.. code-block:: xml
48+
49+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
50+
<class name="Acme\BlogBundle\Entity\Author">
51+
<property name="ipAddress">
52+
<constraint name="Ip" />
53+
</property>
54+
</class>
55+
4756
Options
4857
-------
4958

reference/constraints/Language.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ Basic Usage
4141
protected $preferredLanguage;
4242
}
4343
44+
.. code-block:: xml
45+
46+
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
47+
<class name="Acme\UserBundle\Entity\User">
48+
<property name="preferredLanguage">
49+
<constraint name="Language" />
50+
</property>
51+
</class>
52+
4453
Options
4554
-------
4655

reference/constraints/Length.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ To verify that the ``firstName`` field length of a class is between "2" and
6161
6262
.. code-block:: xml
6363
64-
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
64+
<!-- src/Acme/EventBundle/Resources/config/validation.xml -->
6565
<class name="Acme\EventBundle\Entity\Participant">
6666
<property name="firstName">
6767
<constraint name="Length">

0 commit comments

Comments
 (0)