@@ -842,8 +842,8 @@ Group Sequence
842842--------------
843843
844844In some cases, you want to validate your groups by steps. To do this, you can
845- use the ``GroupSequence `` feature. In this case, an object defines a group sequence
846- , which determines the order groups should be validated.
845+ use the ``GroupSequence `` feature. In this case, an object defines a group
846+ sequence , which determines the order groups should be validated.
847847
848848For example, suppose you have a ``User `` class and want to validate that the
849849username and the password are different only if all other validation passes
@@ -1085,21 +1085,14 @@ Now, change the ``User`` class to implement
10851085:class: `Symfony\\ Component\\ Validator\\ GroupSequenceProviderInterface ` and
10861086add the
10871087:method: `Symfony\\ Component\\ Validator\\ GroupSequenceProviderInterface::getGroupSequence `,
1088- which should return an array of groups to use. Also, add the
1089- ``@Assert\GroupSequenceProvider `` annotation to the class (or ``group_sequence_provider: true `` to the YAML). If you imagine
1090- that a method called ``isPremium `` returns true if the user is a premium member,
1091- then your code might look like this::
1088+ which should return an array of groups to use::
10921089
10931090 // src/Acme/DemoBundle/Entity/User.php
10941091 namespace Acme\DemoBundle\Entity;
10951092
10961093 // ...
10971094 use Symfony\Component\Validator\GroupSequenceProviderInterface;
10981095
1099- /**
1100- * @Assert\GroupSequenceProvider
1101- * ...
1102- */
11031096 class User implements GroupSequenceProviderInterface
11041097 {
11051098 // ...
@@ -1116,6 +1109,66 @@ then your code might look like this::
11161109 }
11171110 }
11181111
1112+ At last, you have to notify the Validator component that your ``User `` class
1113+ provides a sequence of groups to be validated:
1114+
1115+ .. configuration-block ::
1116+
1117+ .. code-block :: yaml
1118+
1119+ # src/Acme/DemoBundle/Resources/config/validation.yml
1120+ Acme\DemoBundle\Entity\User :
1121+ group_sequence_provider : ~
1122+
1123+ .. code-block :: php-annotations
1124+
1125+ // src/Acme/DemoBundle/Entity/User.php
1126+ namespace Acme\DemoBundle\Entity;
1127+
1128+ // ...
1129+
1130+ /**
1131+ * @Assert\GroupSequenceProvider
1132+ */
1133+ class User implements GroupSequenceProviderInterface
1134+ {
1135+ // ...
1136+ }
1137+
1138+ .. code-block :: xml
1139+
1140+ <!-- src/Acme/DemoBundle/Resources/config/validation.xml -->
1141+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1142+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
1143+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1144+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping
1145+ http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
1146+ >
1147+ <class name =" Acme\DemoBundle\Entity\User" >
1148+ <group-sequence-provider />
1149+ <!-- ... -->
1150+ </class >
1151+ </constraint-mapping >
1152+
1153+ .. code-block :: php
1154+
1155+ // src/Acme/DemoBundle/Entity/User.php
1156+ namespace Acme\DemoBundle\Entity;
1157+
1158+ // ...
1159+ use Symfony\Component\Validator\Mapping\ClassMetadata;
1160+
1161+ class User implements GroupSequenceProviderInterface
1162+ {
1163+ // ...
1164+
1165+ public static function loadValidatorMetadata(ClassMetadata $metadata)
1166+ {
1167+ $metadata->setGroupSequenceProvider(true);
1168+ // ...
1169+ }
1170+ }
1171+
11191172 .. _book-validation-raw-values :
11201173
11211174Validating Values and Arrays
0 commit comments