BaseFileValidator
BaseFileValidator is the base validator when validating files.
It provides checking of the size and extension of a file for implementing validators. Parameters: ‘min_size’ The minimum file size in byte, default 1 ‘max_size’ The maximum file size in byte ‘extension’ list of valid extensions (delimited by ’ ’) ‘mime_type’ A regular expression checked against the MIME type of the file as returned by the fileinfo extension. The mime type string to match against is something like “application/pdf”. ‘mime_type_include_charset’ Whether the regex in parameter ‘mime_type’ should be matched against a string containing the charset info (as defined in RFC 2045), e.g. “text/csv; charset=iso-8859-1”. Errors: ‘upload_failed’ The upload of the file failed ‘min_size’ ‘max_size’ ‘extension’ The file doesn’t have the required extension ‘mime_type’ The MIME type check failed
Synopsis
Section titled “Synopsis”abstract class BaseFileValidator extends Validator
| Extends | Validator |
| Since | 1.0.0 |
| Source | Validator/BaseFileValidator.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
getAcceptedParameters(): array<int, string> | Returns the base Validator parameters plus ‘min_size’, ‘max_size’, ‘extension’, ‘mime_type’ and ‘mime_type_include_charset’, shared by every file validator. |
| [`initialize(Context $context, array<string, mixed> $parameters = [], array<int | string, mixed> $arguments = [], array<string, string> $errors = []): void`](#initialize) |
validate(): bool | Validates the input |
getAcceptedParameters()
Section titled “getAcceptedParameters()”public static function getAcceptedParameters(): array<int, string>
Returns the base Validator parameters plus ‘min_size’, ‘max_size’, ‘extension’, ‘mime_type’ and ‘mime_type_include_charset’, shared by every file validator.
‘min_size’ and ‘max_size’ bound the uploaded file’s size in bytes, the minimum defaulting to 1 so a zero-byte upload fails. ‘extension’ is a list of acceptable filename extensions, given either as an array or as a space-delimited string, matched case-insensitively against the client filename. ‘mime_type’ is a PCRE matched against the type fileinfo detects from the file’s own content, and requires the fileinfo extension to be loaded; ‘mime_type_include_charset’ makes that match run against the type with the charset appended (“text/csv; charset=iso-8859-1”) rather than the bare type. Subclasses merge their own names onto this set.
Returns array``<``int``, ``string``> — The accepted parameter names.
initialize()
Section titled “initialize()”public function initialize(Context $context, array<string, mixed> $parameters = [], array<int|string, mixed> $arguments = [], array<string, string> $errors = []): void
Initialize this validator.
An array of error messages.
| Parameter | Type | Description |
|---|---|---|
$context | Context | The Context. |
$parameters | array``<``string``, ``mixed``> | An array of validator parameters. |
$arguments | `array<int“ | string, mixed>` |
$errors | array``<``string``, ``string``> | An array of error messages. |
validate()
Section titled “validate()”protected function validate(): bool
Validates the input
Returns bool — The file is valid according to given parameters.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
execute() | Validator | Executes the validator. |
getArguments() | Validator | Returns all arguments which should be validated. |
getBase() | Validator | Returns the base path of this validator. |
getBaseKeys() | Validator | Returns the “keys” in the path of the base |
getContext() | Validator | Retrieve the current application context. |
getDependencyManager() | Validator | Returns the depency manager of the parent container if any. |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getLastKey() | Validator | Returns the last “keys” in the path of the base |
getMutatedRequest() | Validator | The WebRequest this validator ended execute() with. |
getName() | Validator | Returns the name of this validator. |
getParameter() | ParameterHolder | Retrieve a parameter. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
getParameters() | ParameterHolder | Retrieve an array of parameters. |
getParentContainer() | Validator | Retrieve the parent container. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
mapErrorCode() | Validator | Converts string severity codes into integer values (see severity constants) critical -> Validator::CRITICAL error -> Validator::ERROR notice -> Validator::NOTICE none -> Validator::NONE success -> not allowed to be specified by the user. |
removeParameter() | ParameterHolder | Remove a parameter. |
reset() | Validator | Returns the validator to its uninitialized state for reuse across requests. |
setErrorMessage() | Validator | Sets an error message override for the given index (the empty string is the default/generic message). |
setParameter() | ParameterHolder | Set a parameter. |
setParameterByRef() | ParameterHolder | Set a parameter by reference. |
setParameters() | ParameterHolder | Set an array of parameters. |
setParametersByRef() | ParameterHolder | Set an array of parameters by reference. |
setParentContainer() | Validator | Sets the parent container. |
shutdown() | Validator | Shuts the validator down. |