FileValidator
extends ConstraintValidator
in package
Base class for constraint validators.
Tags
Table of Contents
- KB_BYTES = 1000
- KIB_BYTES = 1024
- MB_BYTES = 1000000
- MIB_BYTES = 1048576
- 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").
- SUFFICES = [1 => 'bytes', self::KB_BYTES => 'kB', self::MB_BYTES => 'MB', self::KIB_BYTES => 'KiB', self::MIB_BYTES => 'MiB']
- $context : ExecutionContextInterface
- 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.
- factorizeSizes() : array<string|int, mixed>
- Convert the limit to the smallest possible number (i.e. try "MB", then "kB", then "bytes").
- moreDecimalsThan() : bool
Constants
KB_BYTES
public
mixed
KB_BYTES
= 1000
KIB_BYTES
public
mixed
KIB_BYTES
= 1024
MB_BYTES
public
mixed
MB_BYTES
= 1000000
MIB_BYTES
public
mixed
MIB_BYTES
= 1048576
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
SUFFICES
private
mixed
SUFFICES
= [1 => 'bytes', self::KB_BYTES => 'kB', self::MB_BYTES => 'MB', self::KIB_BYTES => 'KiB', self::MIB_BYTES => 'MiB']
Properties
$context
protected
ExecutionContextInterface
$context
Methods
initialize()
Initializes the constraint validator.
public
initialize(ExecutionContextInterface $context) : mixed
Parameters
- $context : ExecutionContextInterface
Return values
mixed —validate()
{@inheritdoc}
public
validate(mixed $value, Constraint $constraint) : mixed
Parameters
- $value : mixed
- $constraint : Constraint
Return values
mixed —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
-
The value to return the type of
Return values
string —The type of the value
formatValue()
Returns a string representation of the value.
protected
formatValue(mixed $value, int $format) : 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
-
The value to format as string
- $format : int
-
A bitwise combination of the format constants in this class
Return values
string —The string representation of the passed value
formatValues()
Returns a string representation of a list of values.
protected
formatValues(array<string|int, mixed> $values, int $format) : 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
-
A bitwise combination of the format constants in this class
Tags
Return values
string —The string representation of the value list
factorizeSizes()
Convert the limit to the smallest possible number (i.e. try "MB", then "kB", then "bytes").
private
factorizeSizes(int $size, int|float $limit, bool $binaryFormat) : array<string|int, mixed>
Parameters
- $size : int
- $limit : int|float
- $binaryFormat : bool
Return values
array<string|int, mixed> —moreDecimalsThan()
private
static moreDecimalsThan(string $double, int $numberOfDecimals) : bool
Parameters
- $double : string
- $numberOfDecimals : int