db backup prior to drupal security update
[yaffs-website] / vendor / symfony / validator / Constraints / GroupSequence.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Constraints;
13
14 use Symfony\Component\Validator\Exception\OutOfBoundsException;
15
16 /**
17  * A sequence of validation groups.
18  *
19  * When validating a group sequence, each group will only be validated if all
20  * of the previous groups in the sequence succeeded. For example:
21  *
22  *     $validator->validate($address, null, new GroupSequence(array('Basic', 'Strict')));
23  *
24  * In the first step, all constraints that belong to the group "Basic" will be
25  * validated. If none of the constraints fail, the validator will then validate
26  * the constraints in group "Strict". This is useful, for example, if "Strict"
27  * contains expensive checks that require a lot of CPU or slow, external
28  * services. You usually don't want to run expensive checks if any of the cheap
29  * checks fail.
30  *
31  * When adding metadata to a class, you can override the "Default" group of
32  * that class with a group sequence:
33  *
34  *     /**
35  *      * @GroupSequence({"Address", "Strict"})
36  *      *\/
37  *     class Address
38  *     {
39  *         // ...
40  *     }
41  *
42  * Whenever you validate that object in the "Default" group, the group sequence
43  * will be validated:
44  *
45  *     $validator->validate($address);
46  *
47  * If you want to execute the constraints of the "Default" group for a class
48  * with an overridden default group, pass the class name as group name instead:
49  *
50  *     $validator->validate($address, null, "Address")
51  *
52  * @Annotation
53  * @Target({"CLASS", "ANNOTATION"})
54  *
55  * @author Bernhard Schussek <bschussek@gmail.com>
56  *
57  * Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0.
58  */
59 class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
60 {
61     /**
62      * The groups in the sequence.
63      *
64      * @var string[]|GroupSequence[]
65      */
66     public $groups;
67
68     /**
69      * The group in which cascaded objects are validated when validating
70      * this sequence.
71      *
72      * By default, cascaded objects are validated in each of the groups of
73      * the sequence.
74      *
75      * If a class has a group sequence attached, that sequence replaces the
76      * "Default" group. When validating that class in the "Default" group, the
77      * group sequence is used instead, but still the "Default" group should be
78      * cascaded to other objects.
79      *
80      * @var string|GroupSequence
81      */
82     public $cascadedGroup;
83
84     /**
85      * Creates a new group sequence.
86      *
87      * @param string[] $groups The groups in the sequence
88      */
89     public function __construct(array $groups)
90     {
91         // Support for Doctrine annotations
92         $this->groups = isset($groups['value']) ? $groups['value'] : $groups;
93     }
94
95     /**
96      * Returns an iterator for this group.
97      *
98      * Implemented for backwards compatibility with Symfony < 2.5.
99      *
100      * @return \Traversable The iterator
101      *
102      * @see \IteratorAggregate::getIterator()
103      * @deprecated since version 2.5, to be removed in 3.0.
104      */
105     public function getIterator()
106     {
107         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
108
109         return new \ArrayIterator($this->groups);
110     }
111
112     /**
113      * Returns whether the given offset exists in the sequence.
114      *
115      * Implemented for backwards compatibility with Symfony < 2.5.
116      *
117      * @param int $offset The offset
118      *
119      * @return bool Whether the offset exists
120      *
121      * @deprecated since version 2.5, to be removed in 3.0.
122      */
123     public function offsetExists($offset)
124     {
125         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
126
127         return isset($this->groups[$offset]);
128     }
129
130     /**
131      * Returns the group at the given offset.
132      *
133      * Implemented for backwards compatibility with Symfony < 2.5.
134      *
135      * @param int $offset The offset
136      *
137      * @return string The group a the given offset
138      *
139      * @throws OutOfBoundsException If the object does not exist
140      *
141      * @deprecated since version 2.5, to be removed in 3.0.
142      */
143     public function offsetGet($offset)
144     {
145         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
146
147         if (!isset($this->groups[$offset])) {
148             throw new OutOfBoundsException(sprintf(
149                 'The offset "%s" does not exist.',
150                 $offset
151             ));
152         }
153
154         return $this->groups[$offset];
155     }
156
157     /**
158      * Sets the group at the given offset.
159      *
160      * Implemented for backwards compatibility with Symfony < 2.5.
161      *
162      * @param int    $offset The offset
163      * @param string $value  The group name
164      *
165      * @deprecated since version 2.5, to be removed in 3.0.
166      */
167     public function offsetSet($offset, $value)
168     {
169         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
170
171         if (null !== $offset) {
172             $this->groups[$offset] = $value;
173
174             return;
175         }
176
177         $this->groups[] = $value;
178     }
179
180     /**
181      * Removes the group at the given offset.
182      *
183      * Implemented for backwards compatibility with Symfony < 2.5.
184      *
185      * @param int $offset The offset
186      *
187      * @deprecated since version 2.5, to be removed in 3.0.
188      */
189     public function offsetUnset($offset)
190     {
191         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
192
193         unset($this->groups[$offset]);
194     }
195
196     /**
197      * Returns the number of groups in the sequence.
198      *
199      * Implemented for backwards compatibility with Symfony < 2.5.
200      *
201      * @return int The number of groups
202      *
203      * @deprecated since version 2.5, to be removed in 3.0.
204      */
205     public function count()
206     {
207         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
208
209         return count($this->groups);
210     }
211 }