FilesSize
extends Size
in package
Validator for the size of all files which will be validated in sum
Table of Contents
Constants
- NOT_FOUND = 'fileSizeNotFound'
- NOT_READABLE = 'fileFilesSizeNotReadable'
- TOO_BIG = 'fileFilesSizeTooBig'
- TOO_SMALL = 'fileFilesSizeTooSmall'
Properties
- $messageTemplates : array<string, string>
- $messageVariables : array<string, mixed>
- $options : array<string, mixed>
- $abstractOptions : AbstractOptions|array<string, mixed>
- $defaultTranslator : TranslatorInterface
- Default translation object for all validate objects
- $defaultTranslatorTextDomain : string
- Default text domain to be used with translator
- $files : array<string|int, mixed>
- Internal file array
- $messageLength : int
- Limits the maximum returned length of an error message
- $messageTemplates : array<string|int, mixed>
- $messageVariables : array<string|int, mixed>
- $options : array<string|int, mixed>
- Options for this validator
- $size : int
- Detected size
- $value : mixed
- The value to be validated
Methods
- __construct() : mixed
- Sets validator options
- __get() : mixed
- Magic function returns the value of the requested property, if and only if it is the value or a message variable.
- __invoke() : bool
- Invoke as command
- getByteString() : bool
- Will bytestring be used?
- getDefaultTranslator() : TranslatorInterface|null
- Get default translation object for all validate objects
- getDefaultTranslatorTextDomain() : string
- Get default translation text domain for all validate objects
- getMax() : int|string
- Returns the maximum file size
- getMessageLength() : int
- Returns the maximum allowed message length
- getMessages() : array<string, string>
- Returns array of validation failure messages
- getMessageTemplates() : array<string, string>
- Returns the message templates from the validator
- getMessageVariables() : array<int, string>
- Returns an array of the names of variables that are used in constructing validation failure messages
- getMin() : int|string
- Returns the minimum file size
- getOption() : mixed
- Returns an option
- getOptions() : array<string, mixed>
- Returns all available options
- getTranslator() : TranslatorInterface|null
- Return translation object
- getTranslatorTextDomain() : string
- Return the translation text domain
- hasDefaultTranslator() : bool
- Is there a default translation object set?
- hasTranslator() : bool
- Does this validator have its own specific translator?
- isTranslatorEnabled() : bool
- Is translation enabled?
- isValid() : bool
- Returns true if and only if the disk usage of all files is at least min and not bigger than max (when max is not null).
- isValueObscured() : bool
- Retrieve flag indicating whether or not value should be obfuscated in messages
- setDefaultTranslator() : void
- Set default translation object for all validate objects
- setDefaultTranslatorTextDomain() : void
- Set default translation text domain for all validate objects
- setMax() : $this
- Sets the maximum file size
- setMessage() : $this
- Sets the validation failure message template for a particular key
- setMessageLength() : void
- Sets the maximum allowed message length
- setMessages() : $this
- Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
- setMin() : $this
- Sets the minimum file size
- setOptions() : $this
- Sets one or multiple options
- setTranslator() : $this
- Set translation object
- setTranslatorEnabled() : $this
- Indicate whether or not translation should be enabled
- setTranslatorTextDomain() : $this
- Set translation text domain
- setValueObscured() : $this
- Set flag indicating whether or not value should be obfuscated in messages
- useByteString() : self
- Should messages return bytes as integer or as string in SI notation
- createMessage() : null|string
- Constructs and returns a validation failure message with the given message key and value.
- error() : void
- fromByteString() : float|int|string
- Returns the unformatted size
- getFileInfo() : array<string|int, mixed>
- Returns array if the procedure is identified
- getSize() : int
- Retrieve current detected file size
- getValue() : mixed
- Returns the validation value
- setSize() : $this
- Set current size
- setValue() : void
- Sets the value to be validated and clears the messages and errors arrays
- throwError() : false
- Throws an error of the given type
- toByteString() : string
- Returns the formatted size
- translateMessage() : string
- Translate a validation message
- getFileBasedFileInfo() : array<string|int, mixed>
- Generate file information array with base method
- getLegacyFileInfo() : array<string|int, mixed>
- Generate file information array with legacy Laminas_File_Transfer API
- getPsr7FileInfo() : array<string|int, mixed>
- Generate file information array with PSR-7 UploadedFileInterface
- getSapiFileInfo() : array<string|int, mixed>
- Generate file information array with SAPI
Constants
NOT_FOUND
public
mixed
NOT_FOUND
= 'fileSizeNotFound'
NOT_READABLE
public
mixed
NOT_READABLE
= 'fileFilesSizeNotReadable'
TOO_BIG
public
mixed
TOO_BIG
= 'fileFilesSizeTooBig'
Tags
TOO_SMALL
public
mixed
TOO_SMALL
= 'fileFilesSizeTooSmall'
Properties
$messageTemplates
public
array<string, string>
$messageTemplates
$messageVariables
public
array<string, mixed>
$messageVariables
$options
public
array<string, mixed>
$options
$abstractOptions
protected
AbstractOptions|array<string, mixed>
$abstractOptions
= [
'messages' => [],
// Array of validation failure messages
'messageTemplates' => [],
// Array of validation failure message templates
'messageVariables' => [],
// Array of additional variables available for validation failure messages
'translator' => null,
// Translation object to used -> Translator\TranslatorInterface
'translatorTextDomain' => null,
// Translation text domain
'translatorEnabled' => true,
// Is translation enabled?
'valueObscured' => false,
]
$defaultTranslator
Default translation object for all validate objects
protected
static TranslatorInterface
$defaultTranslator
$defaultTranslatorTextDomain
Default text domain to be used with translator
protected
static string
$defaultTranslatorTextDomain
= 'default'
$files
Internal file array
protected
array<string|int, mixed>
$files
$messageLength
Limits the maximum returned length of an error message
protected
static int
$messageLength
= -1
$messageTemplates
protected
array<string|int, mixed>
$messageTemplates
= [self::TOO_BIG => "All files in sum should have a maximum size of '%max%' but '%size%' were detected", self::TOO_SMALL => "All files in sum should have a minimum size of '%min%' but '%size%' were detected", self::NOT_READABLE => 'One or more files can not be read']
Error message templates
$messageVariables
protected
array<string|int, mixed>
$messageVariables
= ['min' => ['options' => 'min'], 'max' => ['options' => 'max'], 'size' => 'size']
Error message template variables
$options
Options for this validator
protected
array<string|int, mixed>
$options
= [
'min' => null,
// Minimum file size, if null there is no minimum
'max' => null,
// Maximum file size, if null there is no maximum
'useByteString' => true,
]
$size
Detected size
protected
int
$size
$value
The value to be validated
protected
mixed
$value
Methods
__construct()
Sets validator options
public
__construct([int|array<string|int, mixed>|Traversable $options = null ]) : mixed
Min limits the used disk space for all files, when used with max=null it is the maximum file size It also accepts an array with the keys 'min' and 'max'
Parameters
- $options : int|array<string|int, mixed>|Traversable = null
-
Options for this validator
Tags
__get()
Magic function returns the value of the requested property, if and only if it is the value or a message variable.
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
__invoke()
Invoke as command
public
__invoke(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolgetByteString()
Will bytestring be used?
public
getByteString() : bool
Return values
boolgetDefaultTranslator()
Get default translation object for all validate objects
public
static getDefaultTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetDefaultTranslatorTextDomain()
Get default translation text domain for all validate objects
public
static getDefaultTranslatorTextDomain() : string
Return values
stringgetMax()
Returns the maximum file size
public
getMax([bool $raw = false ]) : int|string
Parameters
- $raw : bool = false
-
Whether or not to force return of the raw value (defaults off)
Return values
int|stringgetMessageLength()
Returns the maximum allowed message length
public
static getMessageLength() : int
Return values
intgetMessages()
Returns array of validation failure messages
public
getMessages() : array<string, string>
Return values
array<string, string>getMessageTemplates()
Returns the message templates from the validator
public
getMessageTemplates() : array<string, string>
Return values
array<string, string>getMessageVariables()
Returns an array of the names of variables that are used in constructing validation failure messages
public
getMessageVariables() : array<int, string>
Return values
array<int, string>getMin()
Returns the minimum file size
public
getMin([bool $raw = false ]) : int|string
Parameters
- $raw : bool = false
-
Whether or not to force return of the raw value (defaults off)
Return values
int|stringgetOption()
Returns an option
public
getOption(string $option) : mixed
Parameters
- $option : string
-
Option to be returned
Tags
Return values
mixed —Returned option
getOptions()
Returns all available options
public
getOptions() : array<string, mixed>
Return values
array<string, mixed> —Array with all available options
getTranslator()
Return translation object
public
getTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetTranslatorTextDomain()
Return the translation text domain
public
getTranslatorTextDomain() : string
Return values
stringhasDefaultTranslator()
Is there a default translation object set?
public
static hasDefaultTranslator() : bool
Return values
boolhasTranslator()
Does this validator have its own specific translator?
public
hasTranslator() : bool
Return values
boolisTranslatorEnabled()
Is translation enabled?
public
isTranslatorEnabled() : bool
Return values
boolisValid()
Returns true if and only if the disk usage of all files is at least min and not bigger than max (when max is not null).
public
isValid(string|array<string|int, mixed> $value[, array<string|int, mixed> $file = null ]) : bool
Parameters
- $value : string|array<string|int, mixed>
-
Real file to check for size
- $file : array<string|int, mixed> = null
-
File data from \Laminas\File\Transfer\Transfer
Return values
boolisValueObscured()
Retrieve flag indicating whether or not value should be obfuscated in messages
public
isValueObscured() : bool
Return values
boolsetDefaultTranslator()
Set default translation object for all validate objects
public
static setDefaultTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : void
Parameters
- $translator : TranslatorInterface|null = null
- $textDomain : string = null
-
(optional)
Tags
setDefaultTranslatorTextDomain()
Set default translation text domain for all validate objects
public
static setDefaultTranslatorTextDomain([string $textDomain = 'default' ]) : void
Parameters
- $textDomain : string = 'default'
setMax()
Sets the maximum file size
public
setMax(int|string $max) : $this
File size can be an integer or a byte string This includes 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' For example: 2000, 2MB, 0.2GB
Parameters
- $max : int|string
-
The maximum file size
Tags
Return values
$this —Provides a fluent interface
setMessage()
Sets the validation failure message template for a particular key
public
setMessage(string $messageString[, string|null $messageKey = null ]) : $this
Parameters
- $messageString : string
- $messageKey : string|null = null
-
OPTIONAL
Tags
Return values
$this —Provides a fluent interface
setMessageLength()
Sets the maximum allowed message length
public
static setMessageLength([int $length = -1 ]) : void
Parameters
- $length : int = -1
setMessages()
Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
public
setMessages(array<string, string> $messages) : $this
Parameters
- $messages : array<string, string>
Return values
$thissetMin()
Sets the minimum file size
public
setMin(int|string $min) : $this
File size can be an integer or a byte string This includes 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' For example: 2000, 2MB, 0.2GB
Parameters
- $min : int|string
-
The minimum file size
Tags
Return values
$this —Provides a fluent interface
setOptions()
Sets one or multiple options
public
setOptions([array<string, mixed>|Traversable<string, mixed> $options = [] ]) : $this
Parameters
- $options : array<string, mixed>|Traversable<string, mixed> = []
-
Options to set
Tags
Return values
$this —Provides fluid interface
setTranslator()
Set translation object
public
setTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : $this
Parameters
- $translator : TranslatorInterface|null = null
-
[optional] translator. Default is null, which sets no translator.
- $textDomain : string = null
-
(optional)
Tags
Return values
$thissetTranslatorEnabled()
Indicate whether or not translation should be enabled
public
setTranslatorEnabled([bool $enabled = true ]) : $this
Parameters
- $enabled : bool = true
Return values
$thissetTranslatorTextDomain()
Set translation text domain
public
setTranslatorTextDomain([string $textDomain = 'default' ]) : $this
Parameters
- $textDomain : string = 'default'
Return values
$thissetValueObscured()
Set flag indicating whether or not value should be obfuscated in messages
public
setValueObscured(bool $flag) : $this
Parameters
- $flag : bool
Return values
$thisuseByteString()
Should messages return bytes as integer or as string in SI notation
public
useByteString([bool $byteString = true ]) : self
Parameters
- $byteString : bool = true
-
Use bytestring ?
Return values
selfcreateMessage()
Constructs and returns a validation failure message with the given message key and value.
protected
createMessage(string $messageKey, string|array<string|int, mixed>|object $value) : null|string
Returns null if and only if $messageKey does not correspond to an existing template.
If a translator is available and a translation exists for $messageKey, the translation will be used.
Parameters
- $messageKey : string
- $value : string|array<string|int, mixed>|object
Return values
null|stringerror()
protected
error(string|null $messageKey[, null|string|array<string|int, mixed>|object $value = null ]) : void
Parameters
- $messageKey : string|null
- $value : null|string|array<string|int, mixed>|object = null
-
OPTIONAL
fromByteString()
Returns the unformatted size
protected
fromByteString(string $size) : float|int|string
Parameters
- $size : string
Return values
float|int|stringgetFileInfo()
Returns array if the procedure is identified
protected
getFileInfo(string|array<string|int, mixed>|object $value[, null|array<string|int, mixed> $file = null ][, bool $hasType = false ][, bool $hasBasename = false ]) : array<string|int, mixed>
Parameters
- $value : string|array<string|int, mixed>|object
-
Filename to check
- $file : null|array<string|int, mixed> = null
-
File data (when using legacy Laminas_File_Transfer API)
- $hasType : bool = false
-
Return with filetype (optional)
- $hasBasename : bool = false
-
Return with basename - is calculated from location path (optional)
Return values
array<string|int, mixed>getSize()
Retrieve current detected file size
protected
getSize() : int
Return values
intgetValue()
Returns the validation value
protected
getValue() : mixed
Return values
mixed —Value to be validated
setSize()
Set current size
protected
setSize(int $size) : $this
Parameters
- $size : int
Return values
$thissetValue()
Sets the value to be validated and clears the messages and errors arrays
protected
setValue(mixed $value) : void
Parameters
- $value : mixed
throwError()
Throws an error of the given type
protected
throwError(string $file, string $errorType) : false
Parameters
- $file : string
- $errorType : string
Return values
falsetoByteString()
Returns the formatted size
protected
toByteString(int $size) : string
Parameters
- $size : int
Return values
stringtranslateMessage()
Translate a validation message
protected
translateMessage(string $messageKey, string $message) : string
Parameters
- $messageKey : string
- $message : string
Return values
stringgetFileBasedFileInfo()
Generate file information array with base method
private
getFileBasedFileInfo(string $file[, bool $hasType = false ][, bool $hasBasename = false ]) : array<string|int, mixed>
Parameters
- $file : string
-
File path
- $hasType : bool = false
-
Return with filetype
- $hasBasename : bool = false
-
Filename is calculated from location path
Return values
array<string|int, mixed>getLegacyFileInfo()
Generate file information array with legacy Laminas_File_Transfer API
private
getLegacyFileInfo(array<string|int, mixed> $file[, bool $hasType = false ][, bool $hasBasename = false ]) : array<string|int, mixed>
Parameters
- $file : array<string|int, mixed>
-
File data
- $hasType : bool = false
-
Return with filetype
- $hasBasename : bool = false
-
Basename is calculated from location path
Return values
array<string|int, mixed>getPsr7FileInfo()
Generate file information array with PSR-7 UploadedFileInterface
private
getPsr7FileInfo(UploadedFileInterface $file[, bool $hasType = false ][, bool $hasBasename = false ]) : array<string|int, mixed>
Parameters
- $file : UploadedFileInterface
- $hasType : bool = false
-
Return with filetype
- $hasBasename : bool = false
-
Filename is calculated from location path
Return values
array<string|int, mixed>getSapiFileInfo()
Generate file information array with SAPI
private
getSapiFileInfo(array<string|int, mixed> $file[, bool $hasType = false ][, bool $hasBasename = false ]) : array<string|int, mixed>
Parameters
- $file : array<string|int, mixed>
-
File data from SAPI
- $hasType : bool = false
-
Return with filetype
- $hasBasename : bool = false
-
Filename is calculated from location path