GroupSequence

class GroupSequence implements ArrayAccess, IteratorAggregate, Countable

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(array('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")

Properties

string[]|GroupSequence[] $groups The groups in the sequence.
string|GroupSequence $cascadedGroup The group in which cascaded objects are validated when validating this sequence.

Methods

__construct(array $groups)

Creates a new group sequence.

Traversable getIterator() deprecated

Returns an iterator for this group.

bool offsetExists(int $offset) deprecated

Returns whether the given offset exists in the sequence.

string offsetGet(int $offset) deprecated

Returns the group at the given offset.

offsetSet(int $offset, string $value) deprecated

Sets the group at the given offset.

offsetUnset(int $offset) deprecated

Removes the group at the given offset.

int count() deprecated

Returns the number of groups in the sequence.

Details

__construct(array $groups)

Creates a new group sequence.

Parameters

array $groups The groups in the sequence

Traversable getIterator() deprecated

deprecated

since version 2.5, to be removed in 3.0.

Returns an iterator for this group.

Implemented for backwards compatibility with Symfony < 2.5.

Return Value

Traversable The iterator

See also

\IteratorAggregate::getIterator()

bool offsetExists(int $offset) deprecated

deprecated

since version 2.5, to be removed in 3.0.

Returns whether the given offset exists in the sequence.

Implemented for backwards compatibility with Symfony < 2.5.

Parameters

int $offset The offset

Return Value

bool Whether the offset exists

string offsetGet(int $offset) deprecated

deprecated

since version 2.5, to be removed in 3.0.

Returns the group at the given offset.

Implemented for backwards compatibility with Symfony < 2.5.

Parameters

int $offset The offset

Return Value

string The group a the given offset

Exceptions

OutOfBoundsException If the object does not exist

offsetSet(int $offset, string $value) deprecated

deprecated

since version 2.5, to be removed in 3.0.

Sets the group at the given offset.

Implemented for backwards compatibility with Symfony < 2.5.

Parameters

int $offset The offset
string $value The group name

offsetUnset(int $offset) deprecated

deprecated

since version 2.5, to be removed in 3.0.

Removes the group at the given offset.

Implemented for backwards compatibility with Symfony < 2.5.

Parameters

int $offset The offset

int count() deprecated

deprecated

since version 2.5, to be removed in 3.0.

Returns the number of groups in the sequence.

Implemented for backwards compatibility with Symfony < 2.5.

Return Value

int The number of groups

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.8/Symfony/Component/Validator/Constraints/GroupSequence.html