4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Constraints;
15 * A sequence of validation groups.
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:
20 * $validator->validate($address, null, new GroupSequence(array('Basic', 'Strict')));
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
29 * When adding metadata to a class, you can override the "Default" group of
30 * that class with a group sequence:
33 * * @GroupSequence({"Address", "Strict"})
40 * Whenever you validate that object in the "Default" group, the group sequence
43 * $validator->validate($address);
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:
48 * $validator->validate($address, null, "Address")
51 * @Target({"CLASS", "ANNOTATION"})
53 * @author Bernhard Schussek <bschussek@gmail.com>
58 * The groups in the sequence.
60 * @var string[]|array[]|GroupSequence[]
65 * The group in which cascaded objects are validated when validating
68 * By default, cascaded objects are validated in each of the groups of
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.
76 * @var string|GroupSequence
78 public $cascadedGroup;
81 * Creates a new group sequence.
83 * @param string[] $groups The groups in the sequence
85 public function __construct(array $groups)
87 // Support for Doctrine annotations
88 $this->groups = isset($groups['value']) ? $groups['value'] : $groups;