Definition at line 35 of file Size.php.
◆ __construct()
Sets validator options
If $options is a integer, it will be used as maximum filesize As Array is accepts the following keys: 'min': Minimum filesize 'max': Maximum filesize 'bytestring': Use bytestring or real size for messages
- Parameters
-
integer | array | $options | Options for the adapter |
- Exceptions
-
Definition at line 104 of file Size.php.
111 #require_once 'Zend/Validate/Exception.php'; 115 if (1 < func_num_args()) {
116 $argv = func_get_args();
118 $options[
'max'] = array_shift($argv);
120 $options[
'bytestring'] = array_shift($argv);
124 if (isset(
$options[
'bytestring'])) {
elseif(isset( $params[ 'redirect_parent']))
setUseByteString($byteString=true)
◆ _fromByteString()
Returns the unformatted size
- Parameters
-
- Returns
- integer
Definition at line 340 of file Size.php.
342 if (is_numeric($size)) {
343 return (integer) $size;
346 $type = trim(substr($size, -2, 1));
348 $value = substr($size, 0, -1);
349 if (!is_numeric(
$value)) {
353 switch (strtoupper(
$type)) {
355 $value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024);
358 $value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024);
361 $value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024);
364 $value *= (1024 * 1024 * 1024 * 1024 * 1024);
367 $value *= (1024 * 1024 * 1024 * 1024);
370 $value *= (1024 * 1024 * 1024);
◆ _getSize()
Retrieve current detected file size
- Returns
- int
Definition at line 248 of file Size.php.
◆ _setSize()
◆ _throw()
_throw |
( |
|
$file, |
|
|
|
$errorType |
|
) |
| |
|
protected |
Throws an error of the given type
- Parameters
-
string | $file | |
string | $errorType | |
- Returns
- false
Definition at line 392 of file Size.php.
394 if ($file !==
null) {
395 $this->_value = $file[
'name'];
398 $this->
_error($errorType);
_error($messageKey, $value=null)
◆ _toByteString()
Returns the formatted size
- Parameters
-
- Returns
- string
Definition at line 324 of file Size.php.
326 $sizes = array(
'B',
'kB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB');
327 for (
$i=0; $size >= 1024 &&
$i < 9;
$i++) {
331 return round($size, 2) . $sizes[
$i];
◆ getMax()
Returns the maximum filesize
- Parameters
-
bool | $raw | Whether or not to force return of the raw value (defaults off) |
- Returns
- integer|string
Definition at line 207 of file Size.php.
◆ getMin()
Returns the minimum filesize
- Parameters
-
bool | $raw | Whether or not to force return of the raw value (defaults off) |
- Returns
- integer|string
Definition at line 165 of file Size.php.
◆ isValid()
isValid |
( |
|
$value, |
|
|
|
$file = null |
|
) |
| |
Defined by Zend_Validate_Interface
Returns true if and only if the filesize of $value is at least min and not bigger than max (when max is not null).
- Parameters
-
- Returns
- boolean
Definition at line 275 of file Size.php.
278 #require_once 'Zend/Loader.php'; 280 return $this->
_throw($file, self::NOT_FOUND);
285 $this->_size = $size;
288 $min = $this->
getMin(
true);
289 $max = $this->
getMax(
true);
290 if (($min !==
null) && ($size < $min)) {
294 $this->
_throw($file, self::TOO_SMALL);
296 $this->_size = $size;
298 $this->
_throw($file, self::TOO_SMALL);
303 if (($max !==
null) && ($max < $size)) {
307 $this->
_throw($file, self::TOO_BIG);
309 $this->_size = $size;
311 $this->
_throw($file, self::TOO_BIG);
315 return empty($this->_messages);
static isReadable($filename)
_throw($file, $errorType)
◆ setMax()
Sets the maximum filesize
- Parameters
-
integer | $max | The maximum filesize |
- Exceptions
-
- Returns
- Zend_Validate_StringLength Provides a fluent interface
Definition at line 224 of file Size.php.
226 if (!is_string($max) && !is_numeric($max)) {
227 #require_once 'Zend/Validate/Exception.php'; 232 $min = $this->
getMin(
true);
233 if (($min !==
null) && ($max < $min)) {
234 #require_once 'Zend/Validate/Exception.php';
◆ setMin()
Sets the minimum filesize
- Parameters
-
integer | $min | The minimum filesize |
- Exceptions
-
- Returns
- Zend_Validate_File_Size Provides a fluent interface
Definition at line 182 of file Size.php.
184 if (!is_string($min) and !is_numeric($min)) {
185 #require_once 'Zend/Validate/Exception.php'; 190 $max = $this->
getMax(
true);
191 if (($max !==
null) && ($min > $max)) {
192 #require_once 'Zend/Validate/Exception.php';
◆ setUseByteString()
setUseByteString |
( |
|
$byteString = true | ) |
|
Returns the minimum filesize
- Parameters
-
boolean | $byteString | Use bytestring ? |
- Returns
- integer
Definition at line 143 of file Size.php.
145 $this->_useByteString = (bool) $byteString;
◆ useByteString()
Will bytestring be used?
- Returns
- boolean
Definition at line 154 of file Size.php.
◆ $_max
◆ $_messageTemplates
Initial value:= array(
self::TOO_BIG => "Maximum allowed size for file '%value%' is '%max%' but '%size%' detected",
self::TOO_SMALL => "Minimum expected size for file '%value%' is '%min%' but '%size%' detected",
self::NOT_FOUND => "File '%value%' is not readable or does not exist",
)
Definition at line 48 of file Size.php.
◆ $_messageVariables
Initial value:= array(
'min' => '_min',
'max' => '_max',
'size' => '_size',
)
Definition at line 57 of file Size.php.
◆ $_min
◆ $_size
◆ $_useByteString
◆ NOT_FOUND
const NOT_FOUND = 'fileSizeNotFound' |
◆ TOO_BIG
const TOO_BIG = 'fileSizeTooBig' |
#+ @const string Error constants
Definition at line 40 of file Size.php.
◆ TOO_SMALL
const TOO_SMALL = 'fileSizeTooSmall' |
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Validate/File/Size.php