Skip to content

Commit fed881d

Browse files
committed
Merge branch '2.3' into 2.4
2 parents 136f98c + b453fa6 commit fed881d

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

book/validation.rst

+63-10
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,8 @@ Group Sequence
839839
--------------
840840

841841
In some cases, you want to validate your groups by steps. To do this, you can
842-
use the ``GroupSequence`` feature. In this case, an object defines a group sequence
843-
, which determines the order groups should be validated.
842+
use the ``GroupSequence`` feature. In this case, an object defines a group
843+
sequence, which determines the order groups should be validated.
844844

845845
For example, suppose you have a ``User`` class and want to validate that the
846846
username and the password are different only if all other validation passes
@@ -1082,21 +1082,14 @@ Now, change the ``User`` class to implement
10821082
:class:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface` and
10831083
add the
10841084
:method:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface::getGroupSequence`,
1085-
which should return an array of groups to use. Also, add the
1086-
``@Assert\GroupSequenceProvider`` annotation to the class (or ``group_sequence_provider: true`` to the YAML). If you imagine
1087-
that a method called ``isPremium`` returns true if the user is a premium member,
1088-
then your code might look like this::
1085+
which should return an array of groups to use::
10891086

10901087
// src/Acme/DemoBundle/Entity/User.php
10911088
namespace Acme\DemoBundle\Entity;
10921089

10931090
// ...
10941091
use Symfony\Component\Validator\GroupSequenceProviderInterface;
10951092

1096-
/**
1097-
* @Assert\GroupSequenceProvider
1098-
* ...
1099-
*/
11001093
class User implements GroupSequenceProviderInterface
11011094
{
11021095
// ...
@@ -1113,6 +1106,66 @@ then your code might look like this::
11131106
}
11141107
}
11151108

1109+
At last, you have to notify the Validator component that your ``User`` class
1110+
provides a sequence of groups to be validated:
1111+
1112+
.. configuration-block::
1113+
1114+
.. code-block:: yaml
1115+
1116+
# src/Acme/DemoBundle/Resources/config/validation.yml
1117+
Acme\DemoBundle\Entity\User:
1118+
group_sequence_provider: ~
1119+
1120+
.. code-block:: php-annotations
1121+
1122+
// src/Acme/DemoBundle/Entity/User.php
1123+
namespace Acme\DemoBundle\Entity;
1124+
1125+
// ...
1126+
1127+
/**
1128+
* @Assert\GroupSequenceProvider
1129+
*/
1130+
class User implements GroupSequenceProviderInterface
1131+
{
1132+
// ...
1133+
}
1134+
1135+
.. code-block:: xml
1136+
1137+
<!-- src/Acme/DemoBundle/Resources/config/validation.xml -->
1138+
<?xml version="1.0" encoding="UTF-8" ?>
1139+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
1140+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1141+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
1142+
http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
1143+
>
1144+
<class name="Acme\DemoBundle\Entity\User">
1145+
<group-sequence-provider />
1146+
<!-- ... -->
1147+
</class>
1148+
</constraint-mapping>
1149+
1150+
.. code-block:: php
1151+
1152+
// src/Acme/DemoBundle/Entity/User.php
1153+
namespace Acme\DemoBundle\Entity;
1154+
1155+
// ...
1156+
use Symfony\Component\Validator\Mapping\ClassMetadata;
1157+
1158+
class User implements GroupSequenceProviderInterface
1159+
{
1160+
// ...
1161+
1162+
public static function loadValidatorMetadata(ClassMetadata $metadata)
1163+
{
1164+
$metadata->setGroupSequenceProvider(true);
1165+
// ...
1166+
}
1167+
}
1168+
11161169
.. _book-validation-raw-values:
11171170

11181171
Validating Values and Arrays

components/console/helpers/dialoghelper.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ This methods has 2 new arguments, the full signature is::
130130
string|array $question,
131131
callback $validator,
132132
integer $attempts = false,
133-
string $default = null
133+
string $default = null,
134+
array $autocomplete = null
134135
)
135136

136137
The ``$validator`` is a callback which handles the validation. It should
@@ -139,8 +140,8 @@ in the console, so it is a good practice to put some useful information in it. T
139140
function should also return the value of the user's input if the validation was successful.
140141

141142
You can set the max number of times to ask in the ``$attempts`` argument.
142-
If you reach this max number it will use the default value, which is given
143-
in the last argument. Using ``false`` means the amount of attempts is infinite.
143+
If you reach this max number it will use the default value.
144+
Using ``false`` means the amount of attempts is infinite.
144145
The user will be asked as long as they provide an invalid answer and will only
145146
be able to proceed if their input is valid.
146147

contributing/code/standards.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ Structure
101101

102102
* Declare class properties before methods;
103103

104-
* Declare public methods first, then protected ones and finally private ones;
104+
* Declare public methods first, then protected ones and finally private ones.
105+
The exceptions to this rule are the class constructor and the ``setUp`` and
106+
``tearDown`` methods of PHPUnit tests, which should always be the first methods
107+
to increase readability;
105108

106109
* Use parentheses when instantiating classes regardless of the number of
107110
arguments the constructor has;

0 commit comments

Comments
 (0)