Skip to content

Commit 2633b29

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: changing includes to links Updating book examples to not use deprecated validation methods Updated constraint reference docs for Null->IsNull, False->IsFalse, True->IsTrue Creating placeholder constraint rst docs for deprecated usage Renaming constraint rst files to Is* to preserve edit history Fixes thanks to Stof fixing build failure Tweaks - see #5314
2 parents 2e8d0b7 + 8a409c9 commit 2633b29

File tree

11 files changed

+366
-344
lines changed

11 files changed

+366
-344
lines changed

book/validation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ this method must return ``true``:
630630
class Author
631631
{
632632
/**
633-
* @Assert\True(message = "The password cannot match your first name")
633+
* @Assert\IsTrue(message = "The password cannot match your first name")
634634
*/
635635
public function isPasswordLegal()
636636
{
@@ -675,7 +675,7 @@ this method must return ``true``:
675675
{
676676
public static function loadValidatorMetadata(ClassMetadata $metadata)
677677
{
678-
$metadata->addGetterConstraint('passwordLegal', new Assert\True(array(
678+
$metadata->addGetterConstraint('passwordLegal', new Assert\IsTrue(array(
679679
'message' => 'The password cannot match your first name',
680680
)));
681681
}
@@ -937,7 +937,7 @@ username and the password are different only if all other validation passes
937937
private $password;
938938
939939
/**
940-
* @Assert\True(message="The password cannot match your username", groups={"Strict"})
940+
* @Assert\IsTrue(message="The password cannot match your username", groups={"Strict"})
941941
*/
942942
public function isPasswordLegal()
943943
{
@@ -1011,7 +1011,7 @@ username and the password are different only if all other validation passes
10111011
$metadata->addPropertyConstraint('username', new Assert\NotBlank());
10121012
$metadata->addPropertyConstraint('password', new Assert\NotBlank());
10131013
1014-
$metadata->addGetterConstraint('passwordLegal', new Assert\True(array(
1014+
$metadata->addGetterConstraint('passwordLegal', new Assert\IsTrue(array(
10151015
'message' => 'The password cannot match your first name',
10161016
'groups' => array('Strict'),
10171017
)));

components/config/definition.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ Before defining the children of an array node, you can provide options like:
205205
``addDefaultsIfNotSet()``
206206
If any child nodes have default values, use them if explicit values
207207
haven't been provided.
208+
``normalizeKeys(false)``
209+
If called (with ``false``), keys with dashes are *not* normalized to underscores.
210+
It is recommended to use this with prototype nodes where the user will define
211+
a key-value map, to avoid an unnecessary transformation.
208212

209213
A basic prototyped array configuration can be defined as follows::
210214

@@ -303,6 +307,13 @@ The output configuration will be exactly the same as before. In other words, the
303307
``sf_connection`` and ``default`` configuration keys are lost. The reason is that
304308
the Symfony Config component treats arrays as lists by default.
305309

310+
.. note::
311+
312+
As of writing this, there is an inconsistency: if only one file provides the
313+
configuration in question, the keys (i.e. ``sf_connection`` and ``default``)
314+
are *not* lost. But if more than one file provides the configuration, the keys
315+
are lost as described above.
316+
306317
In order to maintain the array keys use the ``useAttributeAsKey()`` method::
307318

308319
$node

cookbook/event_dispatcher/event_listener.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Request Events, Checking Types
223223
A single page can make several requests (one master request, and then multiple
224224
sub-requests - typically by :ref:`templating-embedding-controller`). For the core
225225
Symfony events, you might need to check to see if the event is for a "master" request
226-
or a "sub request":
226+
or a "sub request"::
227227

228228
// src/AppBundle/EventListener/RequestListener.php
229229
namespace AppBundle\EventListener;

reference/constraints.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Validation Constraints Reference
88
constraints/NotBlank
99
constraints/Blank
1010
constraints/NotNull
11-
constraints/Null
12-
constraints/True
13-
constraints/False
11+
constraints/IsNull
12+
constraints/IsTrue
13+
constraints/IsFalse
1414
constraints/Type
1515

1616
constraints/Email

reference/constraints/Blank.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Blank
33

44
Validates that a value is blank, defined as equal to a blank string or equal
55
to ``null``. To force that a value strictly be equal to ``null``, see the
6-
:doc:`/reference/constraints/Null` constraint. To force that a value is
6+
:doc:`/reference/constraints/IsNull` constraint. To force that a value is
77
*not* blank, see :doc:`/reference/constraints/NotBlank`.
88

99
+----------------+---------------------------------------------------------------------+

reference/constraints/False.rst

Lines changed: 3 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,8 @@
11
False
22
=====
33

4-
Validates that a value is ``false``. Specifically, this checks to see if
5-
the value is exactly ``false``, exactly the integer ``0``, or exactly the
6-
string "``0``".
7-
8-
Also see :doc:`True <True>`.
9-
10-
+----------------+---------------------------------------------------------------------+
11-
| Applies to | :ref:`property or method <validation-property-target>` |
12-
+----------------+---------------------------------------------------------------------+
13-
| Options | - `message`_ |
14-
| | - `payload`_ |
15-
+----------------+---------------------------------------------------------------------+
16-
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\False` |
17-
+----------------+---------------------------------------------------------------------+
18-
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\FalseValidator` |
19-
+----------------+---------------------------------------------------------------------+
20-
21-
Basic Usage
22-
-----------
23-
24-
The ``False`` constraint can be applied to a property or a "getter" method,
25-
but is most commonly useful in the latter case. For example, suppose that
26-
you want to guarantee that some ``state`` property is *not* in a dynamic
27-
``invalidStates`` array. First, you'd create a "getter" method::
28-
29-
protected $state;
30-
31-
protected $invalidStates = array();
32-
33-
public function isStateInvalid()
34-
{
35-
return in_array($this->state, $this->invalidStates);
36-
}
37-
38-
In this case, the underlying object is only valid if the ``isStateInvalid``
39-
method returns **false**:
40-
41-
.. configuration-block::
42-
43-
.. code-block:: php-annotations
44-
45-
// src/AppBundle/Entity/Author.php
46-
namespace AppBundle\Entity;
47-
48-
use Symfony\Component\Validator\Constraints as Assert;
49-
50-
class Author
51-
{
52-
/**
53-
* @Assert\False(
54-
* message = "You've entered an invalid state."
55-
* )
56-
*/
57-
public function isStateInvalid()
58-
{
59-
// ...
60-
}
61-
}
62-
63-
.. code-block:: yaml
64-
65-
# src/AppBundle/Resources/config/validation.yml
66-
AppBundle\Entity\Author
67-
getters:
68-
stateInvalid:
69-
- 'False':
70-
message: You've entered an invalid state.
71-
72-
.. code-block:: xml
73-
74-
<!-- src/AppBundle/Resources/config/validation.xml -->
75-
<?xml version="1.0" encoding="UTF-8" ?>
76-
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
77-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78-
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
79-
80-
<class name="AppBundle\Entity\Author">
81-
<getter property="stateInvalid">
82-
<constraint name="False">
83-
<option name="message">You've entered an invalid state.</option>
84-
</constraint>
85-
</getter>
86-
</class>
87-
</constraint-mapping>
88-
89-
.. code-block:: php
90-
91-
// src/AppBundle/Entity/Author.php
92-
namespace AppBundle\Entity;
93-
94-
use Symfony\Component\Validator\Mapping\ClassMetadata;
95-
use Symfony\Component\Validator\Constraints as Assert;
96-
97-
class Author
98-
{
99-
public static function loadValidatorMetadata(ClassMetadata $metadata)
100-
{
101-
$metadata->addGetterConstraint('stateInvalid', new Assert\False());
102-
}
103-
}
104-
1054
.. caution::
1065

107-
When using YAML, be sure to surround ``False`` with quotes (``'False'``)
108-
or else YAML will convert this into a ``false`` boolean value.
109-
110-
Options
111-
-------
112-
113-
message
114-
~~~~~~~
115-
116-
**type**: ``string`` **default**: ``This value should be false.``
117-
118-
This message is shown if the underlying data is not false.
119-
120-
.. include:: /reference/constraints/_payload-option.rst.inc
6+
The ``False`` constraint is deprecated since Symfony 2.7
7+
and will be removed in Symfony 3.0. Use the
8+
:doc:`/reference/constraints/IsFalse` constraint instead.

reference/constraints/IsFalse.rst

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
IsFalse
2+
=======
3+
4+
Validates that a value is ``false``. Specifically, this checks to see if
5+
the value is exactly ``false``, exactly the integer ``0``, or exactly the
6+
string "``0``".
7+
8+
Also see :doc:`IsTrue <IsTrue>`.
9+
10+
+----------------+-----------------------------------------------------------------------+
11+
| Applies to | :ref:`property or method <validation-property-target>` |
12+
+----------------+-----------------------------------------------------------------------+
13+
| Options | - `message`_ |
14+
| | - `payload`_ |
15+
+----------------+-----------------------------------------------------------------------+
16+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\IsFalse` |
17+
+----------------+-----------------------------------------------------------------------+
18+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IsFalseValidator` |
19+
+----------------+-----------------------------------------------------------------------+
20+
21+
Basic Usage
22+
-----------
23+
24+
The ``IsFalse`` constraint can be applied to a property or a "getter" method,
25+
but is most commonly useful in the latter case. For example, suppose that
26+
you want to guarantee that some ``state`` property is *not* in a dynamic
27+
``invalidStates`` array. First, you'd create a "getter" method::
28+
29+
protected $state;
30+
31+
protected $invalidStates = array();
32+
33+
public function isStateInvalid()
34+
{
35+
return in_array($this->state, $this->invalidStates);
36+
}
37+
38+
In this case, the underlying object is only valid if the ``isStateInvalid``
39+
method returns **false**:
40+
41+
.. configuration-block::
42+
43+
.. code-block:: php-annotations
44+
45+
// src/AppBundle/Entity/Author.php
46+
namespace AppBundle\Entity;
47+
48+
use Symfony\Component\Validator\Constraints as Assert;
49+
50+
class Author
51+
{
52+
/**
53+
* @Assert\IsFalse(
54+
* message = "You've entered an invalid state."
55+
* )
56+
*/
57+
public function isStateInvalid()
58+
{
59+
// ...
60+
}
61+
}
62+
63+
.. code-block:: yaml
64+
65+
# src/AppBundle/Resources/config/validation.yml
66+
AppBundle\Entity\Author
67+
getters:
68+
stateInvalid:
69+
- 'IsFalse':
70+
message: You've entered an invalid state.
71+
72+
.. code-block:: xml
73+
74+
<!-- src/AppBundle/Resources/config/validation.xml -->
75+
<?xml version="1.0" encoding="UTF-8" ?>
76+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
77+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
79+
80+
<class name="AppBundle\Entity\Author">
81+
<getter property="stateInvalid">
82+
<constraint name="IsFalse">
83+
<option name="message">You've entered an invalid state.</option>
84+
</constraint>
85+
</getter>
86+
</class>
87+
</constraint-mapping>
88+
89+
.. code-block:: php
90+
91+
// src/AppBundle/Entity/Author.php
92+
namespace AppBundle\Entity;
93+
94+
use Symfony\Component\Validator\Mapping\ClassMetadata;
95+
use Symfony\Component\Validator\Constraints as Assert;
96+
97+
class Author
98+
{
99+
public static function loadValidatorMetadata(ClassMetadata $metadata)
100+
{
101+
$metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse());
102+
}
103+
}
104+
105+
Options
106+
-------
107+
108+
message
109+
~~~~~~~
110+
111+
**type**: ``string`` **default**: ``This value should be false.``
112+
113+
This message is shown if the underlying data is not false.
114+
115+
.. include:: /reference/constraints/_payload-option.rst.inc

0 commit comments

Comments
 (0)