All
extends Composite
in package
A constraint that is composed of other constraints.
Tags
Table of Contents
Constants
- CLASS_CONSTRAINT = 'class'
- Marks a constraint that can be put onto classes.
- DEFAULT_GROUP = 'Default'
- The name of the group given to all constraints with no explicit group.
- PROPERTY_CONSTRAINT = 'property'
- Marks a constraint that can be put onto properties.
Properties
- $constraints : mixed
- $groups : array<string|int, string>
- The groups that the constraint belongs to.
- $payload : mixed
- Domain-specific data attached to a constraint.
- $errorNames : mixed
- Maps error codes to the names of their constants.
Methods
- __construct() : mixed
- Initializes the constraint with options.
- __get() : mixed
- Returns the value of a lazily initialized option.
- __isset() : bool
- __set() : mixed
- Sets the value of a lazily initialized option.
- addImplicitGroupName() : mixed
- Adds the given group if this constraint is in the Default group.
- getDefaultOption() : string|null
- getErrorName() : string
- Returns the name of the given error code.
- getRequiredOptions() : array<string|int, mixed>
- getTargets() : string|array<string|int, string>
- Returns whether the constraint can be put onto classes, properties or both.
- validatedBy() : string
- Returns the name of the class that validates this constraint.
- getCompositeOption() : string
- Returns the name of the property that contains the nested constraints.
- initializeNestedConstraints() : mixed
- Initializes the nested constraints.
- normalizeOptions() : array<string|int, mixed>
Constants
CLASS_CONSTRAINT
Marks a constraint that can be put onto classes.
public
mixed
CLASS_CONSTRAINT
= 'class'
DEFAULT_GROUP
The name of the group given to all constraints with no explicit group.
public
mixed
DEFAULT_GROUP
= 'Default'
PROPERTY_CONSTRAINT
Marks a constraint that can be put onto properties.
public
mixed
PROPERTY_CONSTRAINT
= 'property'
Properties
$constraints
public
mixed
$constraints
= []
$groups
The groups that the constraint belongs to.
public
array<string|int, string>
$groups
$payload
Domain-specific data attached to a constraint.
public
mixed
$payload
$errorNames
Maps error codes to the names of their constants.
protected
static mixed
$errorNames
= []
Methods
__construct()
Initializes the constraint with options.
public
__construct([mixed $constraints = null ][, array<string|int, mixed> $groups = null ][, mixed $payload = null ]) : mixed
The groups of the composite and its nested constraints are made consistent using the following strategy:
-
If groups are passed explicitly to the composite constraint, but not to the nested constraints, the options of the composite constraint are copied to the nested constraints;
-
If groups are passed explicitly to the nested constraints, but not to the composite constraint, the groups of all nested constraints are merged and used as groups for the composite constraint;
-
If groups are passed explicitly to both the composite and its nested constraints, the groups of the nested constraints must be a subset of the groups of the composite constraint. If not, a is thrown.
All this is done in the constructor, because constraints can then be cached. When constraints are loaded from the cache, no more group checks need to be done.
Parameters
- $constraints : mixed = null
- $groups : array<string|int, mixed> = null
-
An array of validation groups
- $payload : mixed = null
-
Domain-specific data attached to a constraint
__get()
Returns the value of a lazily initialized option.
public
__get(string $option) : mixed
Corresponding properties are added to the object on first access. Hence this method will be called at most once per constraint instance and option name.
Parameters
- $option : string
Tags
__isset()
public
__isset(string $option) : bool
Parameters
- $option : string
Return values
bool__set()
Sets the value of a lazily initialized option.
public
__set(string $option, mixed $value) : mixed
Corresponding properties are added to the object on first access. Hence this method will be called at most once per constraint instance and option name.
Parameters
- $option : string
- $value : mixed
Tags
addImplicitGroupName()
Adds the given group if this constraint is in the Default group.
public
addImplicitGroupName(string $group) : mixed
Parameters
- $group : string
getDefaultOption()
public
getDefaultOption() : string|null
Return values
string|nullgetErrorName()
Returns the name of the given error code.
public
static getErrorName(string $errorCode) : string
Parameters
- $errorCode : string
Tags
Return values
stringgetRequiredOptions()
public
getRequiredOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getTargets()
Returns whether the constraint can be put onto classes, properties or both.
public
getTargets() : string|array<string|int, string>
This method should return one or more of the constants Constraint::CLASS_CONSTRAINT and Constraint::PROPERTY_CONSTRAINT.
Return values
string|array<string|int, string> —One or more constant values
validatedBy()
Returns the name of the class that validates this constraint.
public
validatedBy() : string
By default, this is the fully qualified name of the constraint class suffixed with "Validator". You can override this method to change that behavior.
Return values
stringgetCompositeOption()
Returns the name of the property that contains the nested constraints.
protected
getCompositeOption() : string
Return values
stringinitializeNestedConstraints()
Initializes the nested constraints.
protected
initializeNestedConstraints() : mixed
This method can be overwritten in subclasses to clean up the nested constraints passed to the constructor.
Tags
normalizeOptions()
protected
normalizeOptions(mixed $options) : array<string|int, mixed>
Parameters
- $options : mixed