UuidValidator
extends ConstraintValidator
in package
Validates whether the value is a valid UUID (also known as GUID).
Strict validation will allow a UUID as specified per RFC 4122. Loose validation will allow any type of UUID.
Tags
Table of Contents
Constants
- LOOSE_FIRST_HYPHEN_POSITION = 4
- LOOSE_MAX_LENGTH = 39
- OBJECT_TO_STRING = 2
- Whether to cast objects with a "__toString()" method to strings.
- PRETTY_DATE = 1
- Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
- STRICT_FIRST_HYPHEN_POSITION = 8
- STRICT_LAST_HYPHEN_POSITION = 23
- STRICT_LENGTH = 36
- STRICT_VARIANT_POSITION = 19
- STRICT_VERSION_POSITION = 14
Properties
Methods
- initialize() : mixed
- Initializes the constraint validator.
- validate() : mixed
- {@inheritdoc}
- formatTypeOf() : string
- Returns a string representation of the type of the value.
- formatValue() : string
- Returns a string representation of the value.
- formatValues() : string
- Returns a string representation of a list of values.
- validateLoose() : mixed
- validateStrict() : mixed
Constants
LOOSE_FIRST_HYPHEN_POSITION
public
mixed
LOOSE_FIRST_HYPHEN_POSITION
= 4
LOOSE_MAX_LENGTH
public
mixed
LOOSE_MAX_LENGTH
= 39
OBJECT_TO_STRING
Whether to cast objects with a "__toString()" method to strings.
public
mixed
OBJECT_TO_STRING
= 2
PRETTY_DATE
Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
public
mixed
PRETTY_DATE
= 1
STRICT_FIRST_HYPHEN_POSITION
public
mixed
STRICT_FIRST_HYPHEN_POSITION
= 8
STRICT_LAST_HYPHEN_POSITION
public
mixed
STRICT_LAST_HYPHEN_POSITION
= 23
STRICT_LENGTH
public
mixed
STRICT_LENGTH
= 36
STRICT_VARIANT_POSITION
public
mixed
STRICT_VARIANT_POSITION
= 19
STRICT_VERSION_POSITION
public
mixed
STRICT_VERSION_POSITION
= 14
Properties
$context
protected
ExecutionContextInterface
$context
Methods
initialize()
Initializes the constraint validator.
public
initialize(ExecutionContextInterface $context) : mixed
Parameters
- $context : ExecutionContextInterface
validate()
{@inheritdoc}
public
validate(mixed $value, Constraint $constraint) : mixed
Parameters
- $value : mixed
- $constraint : Constraint
formatTypeOf()
Returns a string representation of the type of the value.
protected
formatTypeOf(mixed $value) : string
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
- $value : mixed
Return values
stringformatValue()
Returns a string representation of the value.
protected
formatValue(mixed $value[, int $format = 0 ]) : string
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 objects will be formatted with the . If it is not available, they 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
- $value : mixed
- $format : int = 0
-
A bitwise combination of the format constants in this class
Return values
stringformatValues()
Returns a string representation of a list of values.
protected
formatValues(array<string|int, mixed> $values[, int $format = 0 ]) : string
Each of the values is converted to a string using . The values are then concatenated with commas.
Parameters
- $values : array<string|int, mixed>
-
A list of values
- $format : int = 0
-
A bitwise combination of the format constants in this class
Tags
Return values
stringvalidateLoose()
private
validateLoose(string $value, Uuid $constraint) : mixed
Parameters
- $value : string
- $constraint : Uuid
validateStrict()
private
validateStrict(string $value, Uuid $constraint) : mixed
Parameters
- $value : string
- $constraint : Uuid