Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Validator\Constraints; Chris@0: Chris@0: /** Chris@0: * A sequence of validation groups. Chris@0: * Chris@0: * When validating a group sequence, each group will only be validated if all Chris@0: * of the previous groups in the sequence succeeded. For example: Chris@0: * Chris@17: * $validator->validate($address, null, new GroupSequence(['Basic', 'Strict'])); Chris@0: * Chris@0: * In the first step, all constraints that belong to the group "Basic" will be Chris@0: * validated. If none of the constraints fail, the validator will then validate Chris@0: * the constraints in group "Strict". This is useful, for example, if "Strict" Chris@0: * contains expensive checks that require a lot of CPU or slow, external Chris@0: * services. You usually don't want to run expensive checks if any of the cheap Chris@0: * checks fail. Chris@0: * Chris@0: * When adding metadata to a class, you can override the "Default" group of Chris@0: * that class with a group sequence: Chris@0: * Chris@0: * /** Chris@0: * * @GroupSequence({"Address", "Strict"}) Chris@0: * *\/ Chris@0: * class Address Chris@0: * { Chris@0: * // ... Chris@0: * } Chris@0: * Chris@0: * Whenever you validate that object in the "Default" group, the group sequence Chris@0: * will be validated: Chris@0: * Chris@0: * $validator->validate($address); Chris@0: * Chris@0: * If you want to execute the constraints of the "Default" group for a class Chris@0: * with an overridden default group, pass the class name as group name instead: Chris@0: * Chris@0: * $validator->validate($address, null, "Address") Chris@0: * Chris@0: * @Annotation Chris@0: * @Target({"CLASS", "ANNOTATION"}) Chris@0: * Chris@0: * @author Bernhard Schussek Chris@0: */ Chris@0: class GroupSequence Chris@0: { Chris@0: /** Chris@0: * The groups in the sequence. Chris@0: * Chris@0: * @var string[]|array[]|GroupSequence[] Chris@0: */ Chris@0: public $groups; Chris@0: Chris@0: /** Chris@0: * The group in which cascaded objects are validated when validating Chris@0: * this sequence. Chris@0: * Chris@0: * By default, cascaded objects are validated in each of the groups of Chris@0: * the sequence. Chris@0: * Chris@0: * If a class has a group sequence attached, that sequence replaces the Chris@0: * "Default" group. When validating that class in the "Default" group, the Chris@0: * group sequence is used instead, but still the "Default" group should be Chris@0: * cascaded to other objects. Chris@0: * Chris@0: * @var string|GroupSequence Chris@0: */ Chris@0: public $cascadedGroup; Chris@0: Chris@0: /** Chris@0: * Creates a new group sequence. Chris@0: * Chris@0: * @param string[] $groups The groups in the sequence Chris@0: */ Chris@0: public function __construct(array $groups) Chris@0: { Chris@0: // Support for Doctrine annotations Chris@0: $this->groups = isset($groups['value']) ? $groups['value'] : $groups; Chris@0: } Chris@0: }