Skip to content

Commit bd21918

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: reference/constraints/All.rst reference/constraints/Collection.rst reference/constraints/Email.rst
2 parents baad982 + 3439aaf commit bd21918

29 files changed

+528
-127
lines changed

components/console/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ You can install the component in many different ways:
2727
configured with an ANSI driver and your console commands invoke other scripts which
2828
emit ANSI color sequences, they will be shown as raw escape characters.
2929

30-
To enable ANSI colour support for Windows, please install `ANSICON_`.
30+
To enable ANSI colour support for Windows, please install `ANSICON`_.
3131

3232
Creating a basic Command
3333
------------------------

reference/constraints/All.rst

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ entry in that array:
3535
3636
.. code-block:: php-annotations
3737
38-
// src/Acme/UserBundle/Entity/User.php
39-
namespace Acme\UserBundle\Entity;
40-
41-
use Symfony\Component\Validator\Constraints as Assert;
42-
43-
class User
44-
{
45-
/**
46-
* @Assert\All({
47-
* @Assert\NotBlank
48-
* @Assert\Length(min = "5"),
49-
* })
50-
*/
51-
protected $favoriteColors = array();
52-
}
38+
// src/Acme/UserBundle/Entity/User.php
39+
namespace Acme\UserBundle\Entity;
40+
41+
use Symfony\Component\Validator\Constraints as Assert;
42+
43+
class User
44+
{
45+
/**
46+
* @Assert\All({
47+
* @Assert\NotBlank
48+
* @Assert\Length(min = "5"),
49+
* })
50+
*/
51+
protected $favoriteColors = array();
52+
}
5353
5454
.. code-block:: xml
5555
@@ -67,6 +67,27 @@ entry in that array:
6767
</property>
6868
</class>
6969
70+
.. code-block:: php
71+
72+
// src/Acme/UserBundle/Enttiy/User.php
73+
namespace Acme\UserBundle\Entity;
74+
75+
use Symfony\Component\Validator\Mapping\ClassMetadata;
76+
use Symfony\Component\Validator\Constraints as Assert;
77+
78+
class User
79+
{
80+
public static function loadValidatorMetadata(ClassMetadata $metadata)
81+
{
82+
$metadata->addPropertyConstraint('favoriteColors', new Assert\All(array(
83+
'constraints' => array(
84+
new Assert\NotBlank(),
85+
new Assert\MinLength(array('limit' => 5)),
86+
),
87+
)));
88+
}
89+
}
90+
7091
Now, each entry in the ``favoriteColors`` array will be validated to not
7192
be blank and to be at least 5 characters long.
7293

reference/constraints/Blank.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ of an ``Author`` class were blank, you could do the following:
2626

2727
.. code-block:: yaml
2828
29-
properties:
30-
firstName:
31-
- Blank: ~
29+
# src/BlogBundle/Resources/config/validation.yml
30+
Acme\BlogBundle\Entity\Author:
31+
properties:
32+
firstName:
33+
- Blank: ~
3234
3335
.. code-block:: php-annotations
3436
3537
// src/Acme/BlogBundle/Entity/Author.php
38+
namespace Acme\BlogBundle\Entity;
39+
3640
use Symfony\Component\Validator\Constraints as Assert;
3741
3842
class Author
@@ -52,6 +56,22 @@ of an ``Author`` class were blank, you could do the following:
5256
</property>
5357
</class>
5458
59+
.. code-block:: php
60+
61+
// src/Acme/BlogBundle/Entity/Author.php
62+
namespace Acme\BlogBundle\Entity;
63+
64+
use Symfony\Component\Validator\Mapping\ClassMetadata;
65+
use Symfony\Component\Validator\Constraints as Assert;
66+
67+
class Author
68+
{
69+
public static function loadValidatorMetadata(ClassMetadata $metadata)
70+
{
71+
$metadata->addPropertyConstraint('firstName', new Assert\Blank());
72+
}
73+
}
74+
5575
Options
5676
-------
5777

reference/constraints/Callback.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Setup
4343
.. code-block:: php-annotations
4444
4545
// src/Acme/BlogBundle/Entity/Author.php
46+
namespace Acme\BlogBundle\Entity;
47+
4648
use Symfony\Component\Validator\Constraints as Assert;
4749
4850
/**
@@ -63,6 +65,24 @@ Setup
6365
</constraint>
6466
</class>
6567
68+
.. code-block:: php
69+
70+
// src/Acme/BlogBundle/Entity/Author.php
71+
namespace Acme\BlogBundle\Entity;
72+
73+
use Symfony\Component\Validator\Mapping\ClassMetadata;
74+
use Symfony\Component\Validator\Constraints as Assert;
75+
76+
class Author
77+
{
78+
public static function loadValidatorMetadata(ClassMetadata $metadata)
79+
{
80+
$metadata->addConstraint(new Assert\Callback(array(
81+
'methods' => array('isAuthorValid'),
82+
)));
83+
}
84+
}
85+
6686
The Callback Method
6787
-------------------
6888

reference/constraints/Choice.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ If your valid choice list is simple, you can pass them in directly via the
6464
.. code-block:: php-annotations
6565
6666
// src/Acme/BlogBundle/Entity/Author.php
67+
namespace Acme\BlogBundle\Entity;
68+
6769
use Symfony\Component\Validator\Constraints as Assert;
6870
6971
class Author
@@ -77,16 +79,18 @@ If your valid choice list is simple, you can pass them in directly via the
7779
.. code-block:: php
7880
7981
// src/Acme/BlogBundle/EntityAuthor.php
82+
namespace Acme\BlogBundle\Entity;
83+
8084
use Symfony\Component\Validator\Mapping\ClassMetadata;
81-
use Symfony\Component\Validator\Constraints\Choice;
85+
use Symfony\Component\Validator\Constraints as Assert;
8286
8387
class Author
8488
{
8589
protected $gender;
8690
8791
public static function loadValidatorMetadata(ClassMetadata $metadata)
8892
{
89-
$metadata->addPropertyConstraint('gender', new Choice(array(
93+
$metadata->addPropertyConstraint('gender', new Assert\Choice(array(
9094
'choices' => array('male', 'female'),
9195
'message' => 'Choose a valid gender',
9296
)));

reference/constraints/Collection.rst

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,25 @@ blank but is no longer than 100 characters in length, you would do the following
5353

5454
.. code-block:: yaml
5555
56-
properties:
57-
profileData:
58-
- Collection:
59-
fields:
60-
personal_email: Email
61-
short_bio:
62-
- NotBlank
63-
- Length:
64-
max: 100
65-
maxMessage: Your short bio is too long!
66-
allowMissingFields: true
56+
# src/BlogBundle/Resources/config/validation.yml
57+
Acme\BlogBundle\Entity\Author:
58+
properties:
59+
profileData:
60+
- Collection:
61+
fields:
62+
personal_email: Email
63+
short_bio:
64+
- NotBlank
65+
- Length:
66+
max: 100
67+
maxMessage: Your short bio is too long!
68+
allowMissingFields: true
6769
6870
.. code-block:: php-annotations
6971
7072
// src/Acme/BlogBundle/Entity/Author.php
73+
namespace Acme\BlogBundle\Entity;
74+
7175
use Symfony\Component\Validator\Constraints as Assert;
7276
7377
class Author
@@ -119,23 +123,24 @@ blank but is no longer than 100 characters in length, you would do the following
119123
.. code-block:: php
120124
121125
// src/Acme/BlogBundle/Entity/Author.php
126+
namespace Acme\BlogBundle\Entity;
127+
122128
use Symfony\Component\Validator\Mapping\ClassMetadata;
123-
use Symfony\Component\Validator\Constraints\Collection;
124-
use Symfony\Component\Validator\Constraints\Email;
125-
use Symfony\Component\Validator\Constraints\Length;
129+
use Symfony\Component\Validator\Constraints as Assert;
126130
127131
class Author
128132
{
129133
private $options = array();
130134
131135
public static function loadValidatorMetadata(ClassMetadata $metadata)
132136
{
133-
$metadata->addPropertyConstraint('profileData', new Collection(array(
137+
$metadata->addPropertyConstraint('profileData', new Assert\Collection(array(
134138
'fields' => array(
135-
'personal_email' => new Email(),
139+
'personal_email' => new Assert\Email(),
136140
'lastName' => array(
137-
new NotBlank(),
138-
new Length(array("max" => 100)),
141+
new Assert\NotBlank(),
142+
new Assert\Length(array("max" => 100)),
143+
),
139144
),
140145
'allowMissingFields' => true,
141146
)));

reference/constraints/Country.rst

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ Basic Usage
2828
2929
.. code-block:: php-annotations
3030
31-
// src/Acme/UserBundle/Entity/User.php
32-
namespace Acme\UserBundle\Entity;
33-
34-
use Symfony\Component\Validator\Constraints as Assert;
35-
36-
class User
37-
{
38-
/**
39-
* @Assert\Country
40-
*/
41-
protected $country;
42-
}
31+
// src/Acme/UserBundle/Entity/User.php
32+
namespace Acme\UserBundle\Entity;
33+
34+
use Symfony\Component\Validator\Constraints as Assert;
35+
36+
class User
37+
{
38+
/**
39+
* @Assert\Country
40+
*/
41+
protected $country;
42+
}
4343
4444
.. code-block:: xml
4545
@@ -50,6 +50,22 @@ Basic Usage
5050
</property>
5151
</class>
5252
53+
.. code-block:: php
54+
55+
// src/Acme/UserBundle/Entity/User.php
56+
namespace Acme\UserBundle\Entity;
57+
58+
use Symfony\Component\Validator\Mapping\ClassMetadata;
59+
use Symfony\Component\Validator\Constraints as Assert;
60+
61+
class User
62+
{
63+
public static function loadValidationMetadata(ClassMetadata $metadata)
64+
{
65+
$metadata->addPropertyConstraint('country', new Assert\Country());
66+
}
67+
}
68+
5369
Options
5470
-------
5571

reference/constraints/Date.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Basic Usage
3131
.. code-block:: php-annotations
3232
3333
// src/Acme/BlogBundle/Entity/Author.php
34+
namespace Acme\BlogBundle\Entity;
35+
3436
use Symfony\Component\Validator\Constraints as Assert;
3537
3638
class Author
@@ -50,6 +52,22 @@ Basic Usage
5052
</property>
5153
</class>
5254
55+
.. code-block:: php
56+
57+
// src/Acme/BlogBundle/Entity/Author.php
58+
namespace Acme\BlogBundle\Entity;
59+
60+
use Symfony\Component\Validator\Mapping\ClassMetadata;
61+
use Symfony\Component\Validator\Constraints as Assert;
62+
63+
class Author
64+
{
65+
public static function loadValidatorMetadata(ClassMetadata $metadata)
66+
{
67+
$metadata->addPropertyConstraint('birthday', new Assert\Date());
68+
}
69+
}
70+
5371
Options
5472
-------
5573

reference/constraints/DateTime.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ Basic Usage
5252
</property>
5353
</class>
5454
55+
.. code-block:: php
56+
57+
// src/Acme/BlogBundle/Entity/Author.php
58+
namespace Acme\BlogBundle\Entity;
59+
60+
use Symfony\Component\Validator\Mapping\ClassMetadata;
61+
use Symfony\Component\Validator\Constraints as Assert;
62+
63+
class Author
64+
{
65+
public static function loadValidatorMetadata(ClassMetadata $metadata)
66+
{
67+
$metadata->addPropertyConstraint('createdAt', new Assert\DataTime());
68+
}
69+
}
70+
5571
Options
5672
-------
5773

reference/constraints/Email.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ Basic Usage
6666
protected $email;
6767
}
6868
69+
.. code-block:: php
70+
71+
// src/Acme/BlogBundle/Entity/Author.php
72+
namespace Acme\BlogBundle\Entity;
73+
74+
use Symfony\Component\Validator\Mapping\ClassMetadata;
75+
use Symfony\Component\Validator\Constraints as Assert;
76+
77+
class Author
78+
{
79+
public static function loadValidatorMetadata(ClassMetadata $metadata)
80+
{
81+
$metadata->addPropertyConstraint('email', new Assert\Email(array(
82+
'message' => 'The email "{{ value }}" is not a valid email.',
83+
'check' => true,
84+
)));
85+
}
86+
}
87+
6988
Options
7089
-------
7190

0 commit comments

Comments
 (0)