1111
1212namespace Symfony \Component \Validator \Constraints ;
1313
14+ use Symfony \Component \Validator \Exception \OutOfBoundsException ;
1415use Traversable ;
1516
1617/**
17- * Annotation for group sequences
18+ * A sequence of validation groups.
19+ *
20+ * When validating a group sequence, each group will only be validated if all
21+ * of the previous groups in the sequence succeeded. For example:
22+ *
23+ * $validator->validateObject($address, new GroupSequence('Basic', 'Strict'));
24+ *
25+ * In the first step, all constraints that belong to the group "Basic" will be
26+ * validated. If none of the constraints fail, the validator will then validate
27+ * the constraints in group "Strict". This is useful, for example, if "Strict"
28+ * contains expensive checks that require a lot of CPU or slow, external
29+ * services. You usually don't want to run expensive checks if any of the cheap
30+ * checks fails.
31+ *
32+ * When adding metadata to a class, you can override the "Default" group of
33+ * that class with a group sequence:
34+ *
35+ * /**
36+ * * @GroupSequence({"Address", "Strict"})
37+ * *\/
38+ * class Address
39+ * {
40+ * // ...
41+ * }
42+ *
43+ * Whenever you validate that object in the "Default" group, the group sequence
44+ * will be validated:
45+ *
46+ * $validator->validateObject($address);
47+ *
48+ * If you want to execute the constraints of the "Default" group for a class
49+ * with an overridden default group, pass the class name as group name instead:
50+ *
51+ * $validator->validateObject($address, "Address")
1852 *
1953 * @Annotation
2054 *
2559class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
2660{
2761 /**
28- * The members of the sequence
29- * @var array
62+ * The groups in the sequence
63+ *
64+ * @var string[]|GroupSequence[]
3065 */
3166 public $ groups ;
3267
3368 /**
34- * The group under which cascaded objects are validated when validating
69+ * The group in which cascaded objects are validated when validating
3570 * this sequence.
3671 *
3772 * By default, cascaded objects are validated in each of the groups of
@@ -46,27 +81,80 @@ class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
4681 */
4782 public $ cascadedGroup ;
4883
84+ /**
85+ * Creates a new group sequence.
86+ *
87+ * @param string[] $groups The groups in the sequence
88+ */
4989 public function __construct (array $ groups )
5090 {
5191 // Support for Doctrine annotations
5292 $ this ->groups = isset ($ groups ['value ' ]) ? $ groups ['value ' ] : $ groups ;
5393 }
5494
95+ /**
96+ * Returns an iterator for this group.
97+ *
98+ * @return Traversable The iterator
99+ *
100+ * @see \IteratorAggregate::getIterator()
101+ *
102+ * @deprecated Implemented for backwards compatibility. To be removed in
103+ * Symfony 3.0.
104+ */
55105 public function getIterator ()
56106 {
57107 return new \ArrayIterator ($ this ->groups );
58108 }
59109
110+ /**
111+ * Returns whether the given offset exists in the sequence.
112+ *
113+ * @param integer $offset The offset
114+ *
115+ * @return Boolean Whether the offset exists
116+ *
117+ * @deprecated Implemented for backwards compatibility. To be removed in
118+ * Symfony 3.0.
119+ */
60120 public function offsetExists ($ offset )
61121 {
62122 return isset ($ this ->groups [$ offset ]);
63123 }
64124
125+ /**
126+ * Returns the group at the given offset.
127+ *
128+ * @param integer $offset The offset
129+ *
130+ * @return string The group a the given offset
131+ *
132+ * @throws OutOfBoundsException If the object does not exist
133+ *
134+ * @deprecated Implemented for backwards compatibility. To be removed in
135+ * Symfony 3.0.
136+ */
65137 public function offsetGet ($ offset )
66138 {
139+ if (!isset ($ this ->groups [$ offset ])) {
140+ throw new OutOfBoundsException (sprintf (
141+ 'The offset "%s" does not exist. ' ,
142+ $ offset
143+ ));
144+ }
145+
67146 return $ this ->groups [$ offset ];
68147 }
69148
149+ /**
150+ * Sets the group at the given offset.
151+ *
152+ * @param integer $offset The offset
153+ * @param string $value The group name
154+ *
155+ * @deprecated Implemented for backwards compatibility. To be removed in
156+ * Symfony 3.0.
157+ */
70158 public function offsetSet ($ offset , $ value )
71159 {
72160 if (null !== $ offset ) {
@@ -78,11 +166,27 @@ public function offsetSet($offset, $value)
78166 $ this ->groups [] = $ value ;
79167 }
80168
169+ /**
170+ * Removes the group at the given offset.
171+ *
172+ * @param integer $offset The offset
173+ *
174+ * @deprecated Implemented for backwards compatibility. To be removed in
175+ * Symfony 3.0.
176+ */
81177 public function offsetUnset ($ offset )
82178 {
83179 unset($ this ->groups [$ offset ]);
84180 }
85181
182+ /**
183+ * Returns the number of groups in the sequence.
184+ *
185+ * @return integer The number of groups
186+ *
187+ * @deprecated Implemented for backwards compatibility. To be removed in
188+ * Symfony 3.0.
189+ */
86190 public function count ()
87191 {
88192 return count ($ this ->groups );
0 commit comments