Skip to content

Commit 131a287

Browse files
committed
Added missing formats
1 parent f60eac8 commit 131a287

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

reference/constraints/File.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ below a certain file size and a valid PDF, add the following:
120120
// src/Acme/BlogBundle/Entity/Author.php
121121
namespace Acme\BlogBundle\Entity;
122122
123+
// ...
123124
use Symfony\Component\Validator\Mapping\ClassMetadata;
124125
use Symfony\Component\Validator\Constraints\File;
125126

reference/constraints/Min.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,37 @@ the following:
4646
protected $age;
4747
}
4848
49+
.. code-block:: xml
50+
51+
<!-- src/Acme/EventBundle/Resources/config/validation.yml -->
52+
<class name="Acme\EventBundle\Entity\Participant">
53+
<property name="age">
54+
<constraint name="Min">
55+
<option name="limit">18</option>
56+
<option name="message">You must be 18 or older to enter</option>
57+
</constraint>
58+
</property>
59+
</class>
60+
61+
.. code-block:: php
62+
63+
// src/Acme/EventBundle/Entity/Participant.php
64+
namespace Acme\EventBundle\Entity\Participant;
65+
66+
use Symfony\Component\Validator\Mapping\ClassMetadata;
67+
use Symfony\Component\Validator\Constraints as Assert;
68+
69+
class Participant
70+
{
71+
public static function loadValidatorMetadata(ClassMetadata $metadata)
72+
{
73+
$metadata->addPropertyConstraint('age', new Assert\Min(array(
74+
'limit' => '18',
75+
'message' => 'You must be 18 or older to enter',
76+
));
77+
}
78+
}
79+
4980
Options
5081
-------
5182

reference/constraints/Regex.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ message:
127127
</property>
128128
</class>
129129
130+
.. code-block:: php
131+
132+
// src/Acme/BlogBundle/Entity/Author.php
133+
namespace Acme\BlogBundle\Entity;
134+
135+
use Symfony\Component\Validator\Mapping\ClassMetadata;
136+
use Symfony\Component\Validator\Constraints as Assert;
137+
138+
class Author
139+
{
140+
public static function loadValidatorMetadata(ClassMetadata $metadata)
141+
{
142+
$metadata->addPropertyConstraint('firstName', new Assert\Regex(array(
143+
'pattern' => '/\d/',
144+
'match' => false,
145+
'message' => 'Your name cannot contain a number',
146+
)));
147+
}
148+
}
149+
130150
Options
131151
-------
132152

0 commit comments

Comments
 (0)