Constraint
abstract class Constraint
Contains the properties of a constraint definition.
A constraint can be defined on a class, a property or a getter method. The Constraint class encapsulates all the configuration required for validating this class, property or getter result successfully.
Constraint instances are immutable and serializable.
Constants
Properties
static protected | $errorNames | Maps error codes to the names of their constants. | |
mixed | $payload | Domain-specific data attached to a constraint. | |
array | $groups | The groups that the constraint belongs to |
Methods
Returns the name of the given error code.
Initializes the constraint with options.
Sets the value of a lazily initialized option.
Returns the value of a lazily initialized option.
No description
Adds the given group if this constraint is in the Default group.
Returns the name of the default option.
Returns the name of the required options.
Returns the name of the class that validates this constraint.
Returns whether the constraint can be put onto classes, properties or both.
Optimizes the serialized value to minimize storage space.
Details
__construct(mixed $options = null)
Initializes the constraint with options.
You should pass an associative array. The keys should be the names of existing properties in this class. The values should be the value for these properties.
Alternatively you can override the method getDefaultOption() to return the name of an existing property. If no associative array is passed, this property is set instead.
You can force that certain options are set by overriding getRequiredOptions() to return the names of these options. If any option is not set here, an exception is thrown.
__set(string $option, mixed $value)
Sets the value of a lazily initialized option.
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.
mixed
__get(string $option)
Returns the value of a lazily initialized option.
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.
addImplicitGroupName(string $group)
Adds the given group if this constraint is in the Default group.
string
getDefaultOption()
Returns the name of the default option.
Override this method to define a default option.
array
getRequiredOptions()
Returns the name of the required options.
Override this method if you want to define required options.
string
validatedBy()
Returns the name of the class that validates this constraint.
By default, this is the fully qualified name of the constraint class suffixed with "Validator". You can override this method to change that behaviour.