Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GroupSequence.php

class GroupSequence

A sequence of validation groups.

When validating a group sequence, each group will only be validated if all of the previous groups in the sequence succeeded. For example:

$validator->validate($address, null, new GroupSequence(['Basic', 'Strict']));

In the first step, all constraints that belong to the group "Basic" will be validated. If none of the constraints fail, the validator will then validate the constraints in group "Strict". This is useful, for example, if "Strict" contains expensive checks that require a lot of CPU or slow, external services. You usually don't want to run expensive checks if any of the cheap checks fail.

When adding metadata to a class, you can override the "Default" group of that class with a group sequence: #[GroupSequence(['Address', 'Strict'])] class Address { // ... }

Whenever you validate that object in the "Default" group, the group sequence will be validated:

$validator->validate($address);

If you want to execute the constraints of the "Default" group for a class with an overridden default group, pass the class name as group name instead:

$validator->validate($address, null, "Address")

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Constraints\GroupSequence

Expanded class hierarchy of GroupSequence

13 files declare their use of GroupSequence
AttributeLoader.php in vendor/symfony/validator/Mapping/Loader/AttributeLoader.php
ClassMetadata.php in vendor/symfony/validator/Mapping/ClassMetadata.php
ClassMetadataInterface.php in vendor/symfony/validator/Mapping/ClassMetadataInterface.php
ConstraintValidatorTestCase.php in vendor/symfony/validator/Test/ConstraintValidatorTestCase.php
ContextualValidatorInterface.php in vendor/symfony/validator/Validator/ContextualValidatorInterface.php

... See full list

1 string reference to 'GroupSequence'
ClassMetadata::__sleep in vendor/symfony/validator/Mapping/ClassMetadata.php
Returns the names of the properties that should be serialized.

File

vendor/symfony/validator/Constraints/GroupSequence.php, line 49

Namespace

Symfony\Component\Validator\Constraints
View source
class GroupSequence {
    
    /**
     * The groups in the sequence.
     *
     * @var array<int, string|string[]|GroupSequence>
     */
    public array $groups;
    
    /**
     * The group in which cascaded objects are validated when validating
     * this sequence.
     *
     * By default, cascaded objects are validated in each of the groups of
     * the sequence.
     *
     * If a class has a group sequence attached, that sequence replaces the
     * "Default" group. When validating that class in the "Default" group, the
     * group sequence is used instead, but still the "Default" group should be
     * cascaded to other objects.
     */
    public string|GroupSequence $cascadedGroup;
    
    /**
     * Creates a new group sequence.
     *
     * @param array<string|string[]|GroupSequence> $groups The groups in the sequence
     */
    public function __construct(array $groups) {
        $this->groups = $groups['value'] ?? $groups;
    }

}

Members

Title Sort descending Modifiers Object type Summary
GroupSequence::$cascadedGroup public property The group in which cascaded objects are validated when validating
this sequence.
GroupSequence::$groups public property The groups in the sequence.
GroupSequence::__construct public function Creates a new group sequence.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal