diff --git a/book/validation.rst b/book/validation.rst
index 0a249c9e99d..ebe84139c60 100644
--- a/book/validation.rst
+++ b/book/validation.rst
@@ -771,6 +771,9 @@ With this configuration, there are two validation groups:
* ``Default`` - contains the constraints not assigned to any other group;
+* ``User`` - contains the constraints that belongs to group ``Default``
+ (this group is usefull for :ref:`book-validation-group-sequence`);
+
* ``registration`` - contains the constraints on the ``email`` and ``password``
fields only.
@@ -779,6 +782,9 @@ as the second argument to the ``validate()`` method::
$errors = $validator->validate($author, array('registration'));
+If no groups are specified, all constraints that belong in group ``Default``
+will be applied.
+
Of course, you'll usually work with validation indirectly through the form
library. For information on how to use validation groups inside forms, see
:ref:`book-forms-validation-groups`.
@@ -786,6 +792,126 @@ library. For information on how to use validation groups inside forms, see
.. index::
single: Validation; Validating raw values
+.. _book-validation-group-sequence:
+
+Group Sequence
+--------------
+
+In some cases, you want to validate your groups by steps. To do this, you can
+use the ``GroupSequence`` feature. In the case an object defines a group sequence,
+the groups in the group sequence will be validated in order.
+
+Group sequences cannot contain the group ``Default``, this would create a
+cycle, but need to contain the group ``{ClassName}`` instead.
+
+For example, suppose you have a ``User`` class and want to validate that the
+username and the password are different only if all other validations passes
+(in order to avoid multiple error messages).
+
+.. configuration-block::
+
+ .. code-block:: yaml
+
+ # src/Acme/BlogBundle/Resources/config/validation.yml
+ Acme\BlogBundle\Entity\User:
+ group_sequence:
+ - User
+ - Strict
+ getters:
+ passwordLegal:
+ - "True":
+ message: "The password cannot match your username"
+ groups: [Strict]
+ properties:
+ username:
+ - NotBlank: ~
+ password:
+ - NotBlank: ~
+
+ .. code-block:: php-annotations
+
+ // src/Acme/BlogBundle/Entity/User.php
+ namespace Acme\BlogBundle\Entity;
+
+ use Symfony\Component\Security\Core\User\UserInterface;
+ use Symfony\Component\Validator\Constraints as Assert;
+
+ /**
+ * @Assert\GroupSequence({"Strict", "User"})
+ */
+ class User implements UserInterface
+ {
+ /**
+ * @Assert\NotBlank
+ */
+ private $username;
+
+ /**
+ * @Assert\NotBlank
+ */
+ private $password;
+
+ /**
+ * @Assert\True(message="The password cannot match your username", groups={"Strict"})
+ */
+ public function isPasswordLegal()
+ {
+ return ($this->username !== $this->password);
+ }
+ }
+
+ .. code-block:: xml
+
+
+
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: