Updated to Drupal 8.5. Core Media not yet in use.
[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 /**
15  * A sequence of validation groups.
16  *
17  * When validating a group sequence, each group will only be validated if all
18  * of the previous groups in the sequence succeeded. For example:
19  *
20  *     $validator->validate($address, null, new GroupSequence(array('Basic', 'Strict')));
21  *
22  * In the first step, all constraints that belong to the group "Basic" will be
23  * validated. If none of the constraints fail, the validator will then validate
24  * the constraints in group "Strict". This is useful, for example, if "Strict"
25  * contains expensive checks that require a lot of CPU or slow, external
26  * services. You usually don't want to run expensive checks if any of the cheap
27  * checks fail.
28  *
29  * When adding metadata to a class, you can override the "Default" group of
30  * that class with a group sequence:
31  *
32  *     /**
33  *      * @GroupSequence({"Address", "Strict"})
34  *      *\/
35  *     class Address
36  *     {
37  *         // ...
38  *     }
39  *
40  * Whenever you validate that object in the "Default" group, the group sequence
41  * will be validated:
42  *
43  *     $validator->validate($address);
44  *
45  * If you want to execute the constraints of the "Default" group for a class
46  * with an overridden default group, pass the class name as group name instead:
47  *
48  *     $validator->validate($address, null, "Address")
49  *
50  * @Annotation
51  * @Target({"CLASS", "ANNOTATION"})
52  *
53  * @author Bernhard Schussek <bschussek@gmail.com>
54  */
55 class GroupSequence
56 {
57     /**
58      * The groups in the sequence.
59      *
60      * @var string[]|array[]|GroupSequence[]
61      */
62     public $groups;
63
64     /**
65      * The group in which cascaded objects are validated when validating
66      * this sequence.
67      *
68      * By default, cascaded objects are validated in each of the groups of
69      * the sequence.
70      *
71      * If a class has a group sequence attached, that sequence replaces the
72      * "Default" group. When validating that class in the "Default" group, the
73      * group sequence is used instead, but still the "Default" group should be
74      * cascaded to other objects.
75      *
76      * @var string|GroupSequence
77      */
78     public $cascadedGroup;
79
80     /**
81      * Creates a new group sequence.
82      *
83      * @param string[] $groups The groups in the sequence
84      */
85     public function __construct(array $groups)
86     {
87         // Support for Doctrine annotations
88         $this->groups = isset($groups['value']) ? $groups['value'] : $groups;
89     }
90 }