Skip to content

Commit 235513a

Browse files
committed
Merge branch '2.1'
2 parents 0c00438 + 79e7558 commit 235513a

35 files changed

+542
-135
lines changed

book/forms.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,17 +1541,17 @@ but here's a short example:
15411541

15421542
.. code-block:: php
15431543
1544-
use Symfony\Component\Validator\Constraints\MinLength;
1544+
use Symfony\Component\Validator\Constraints\Length;
15451545
use Symfony\Component\Validator\Constraints\NotBlank;
15461546
15471547
$builder
15481548
->add('firstName', 'text', array(
1549-
'constraints' => new MinLength(3),
1549+
'constraints' => new Length(array('min' => 3)),
15501550
))
15511551
->add('lastName', 'text', array(
15521552
'constraints' => array(
15531553
new NotBlank(),
1554-
new MinLength(3),
1554+
new Length(array('min' => 3)),
15551555
),
15561556
))
15571557
;

book/security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ Note that you will *not* need to implement a controller for the ``/logout``
15671567
URL as the firewall takes care of everything. You *do*, however, need to create
15681568
a route so that you can use it to generate the URL:
15691569

1570-
.. warning::
1570+
.. caution::
15711571

15721572
As of Symfony 2.1, you *must* have a route that corresponds to your logout
15731573
path. Without this route, logging out will not work.

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
------------------------

components/http_foundation/sessions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Quick example::
4848
start on demand, that is, if any session request is made to read/write session
4949
data.
5050

51-
.. warning::
51+
.. caution::
5252

5353
Symfony sessions are incompatible with PHP ini directive ``session.auto_start = 1``
5454
This directive should be turned off in ``php.ini``, in the webserver directives or

cookbook/controller/error_pages.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ end-user, create a new template located at
5050
</body>
5151
</html>
5252

53+
.. caution::
54+
55+
You **must not** use ``is_granted`` in your error pages (or layout used
56+
by your error pages), because the router runs before the firewall. If
57+
the router throws an exception (for instance, when the route does not
58+
match), then using ``is_granted`` will throw a further exception. You
59+
can use ``is_granted`` safely by saying ``{% if app.security and is_granted('...') %}``.
60+
5361
.. tip::
5462

5563
If you're not familiar with Twig, don't worry. Twig is a simple, powerful

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/Entity/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\Length(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

0 commit comments

Comments
 (0)