class CollectionValidator extends ConstraintValidator

Constants

PRETTY_DATE

Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s").

OBJECT_TO_STRING

Whether to cast objects with a "__toString()" method to strings.

Properties

protected ExecutionContextInterface $context from ConstraintValidator

Methods

initialize(ExecutionContextInterface $context)

Initializes the constraint validator.

buildViolation(string $message, array $parameters = array()) deprecated

Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API.

buildViolationInContext(ExecutionContextInterface $context, string $message, array $parameters = array()) deprecated

Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API.

string
formatTypeOf(mixed $value)

Returns a string representation of the type of the value.

string
formatValue(mixed $value, int $format = 0)

Returns a string representation of the value.

string
formatValues(array $values, int $format = 0)

Returns a string representation of a list of values.

validate(mixed $value, Constraint $constraint)

Checks if the passed value is valid.

Details

in ConstraintValidator at line 44
initialize(ExecutionContextInterface $context)

Initializes the constraint validator.

Parameters

ExecutionContextInterface $context The current validation context

in ConstraintValidator at line 60
protected ConstraintViolationBuilderInterface buildViolation(string $message, array $parameters = array()) deprecated

deprecated since version 2.5, to be removed in 3.0.

Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API.

Parameters

string $message The violation message
array $parameters The message parameters

Return Value

ConstraintViolationBuilderInterface The violation builder

in ConstraintValidator at line 83
protected ConstraintViolationBuilderInterface buildViolationInContext(ExecutionContextInterface $context, string $message, array $parameters = array()) deprecated

deprecated since version 2.5, to be removed in 3.0.

Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API.

Parameters

ExecutionContextInterface $context The context to use
string $message The violation message
array $parameters The message parameters

Return Value

ConstraintViolationBuilderInterface The violation builder

in ConstraintValidator at line 106
protected string formatTypeOf(mixed $value)

Returns a string representation of the type of the value.

This method should be used if you pass the type of a value as message parameter to a constraint violation. Note that such parameters should usually not be included in messages aimed at non-technical people.

Parameters

mixed $value The value to return the type of

Return Value

string The type of the value

in ConstraintValidator at line 133
protected string formatValue(mixed $value, int $format = 0)

Returns a string representation of the value.

This method returns the equivalent PHP tokens for most scalar types (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped in double quotes ("). Objects, arrays and resources are formatted as "object", "array" and "resource". If the $format bitmask contains the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted as RFC-3339 dates ("Y-m-d H:i:s").

Be careful when passing message parameters to a constraint violation that (may) contain objects, arrays or resources. These parameters should only be displayed for technical users. Non-technical users won't know what an "object", "array" or "resource" is and will be confused by the violation message.

Parameters

mixed $value The value to format as string
int $format A bitwise combination of the format constants in this class

Return Value

string The string representation of the passed value

in ConstraintValidator at line 206
protected string formatValues(array $values, int $format = 0)

Returns a string representation of a list of values.

Each of the values is converted to a string using {@link formatValue()}. The values are then concatenated with commas.

Parameters

array $values A list of values
int $format A bitwise combination of the format constants in this class

Return Value

string The string representation of the value list

See also

formatValue()

at line 27
validate(mixed $value, Constraint $constraint)

Checks if the passed value is valid.

Parameters

mixed $value The value that should be validated
Constraint $constraint The constraint for the validation