Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Validate_File_FilesSize Class Reference
Inheritance diagram for Zend_Validate_File_FilesSize:
Zend_Validate_File_Size Zend_Validate_Abstract Zend_Validate_Interface

Public Member Functions

 __construct ($options)
 
 isValid ($value, $file=null)
 
- Public Member Functions inherited from Zend_Validate_File_Size
 __construct ($options)
 
 setUseByteString ($byteString=true)
 
 useByteString ()
 
 getMin ($raw=false)
 
 setMin ($min)
 
 getMax ($raw=false)
 
 setMax ($max)
 
 isValid ($value, $file=null)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 
- Public Member Functions inherited from Zend_Validate_Interface
 isValid ($value)
 

Data Fields

const TOO_BIG = 'fileFilesSizeTooBig'
 
const TOO_SMALL = 'fileFilesSizeTooSmall'
 
const NOT_READABLE = 'fileFilesSizeNotReadable'
 
- Data Fields inherited from Zend_Validate_File_Size
const TOO_BIG = 'fileSizeTooBig'
 
const TOO_SMALL = 'fileSizeTooSmall'
 
const NOT_FOUND = 'fileSizeNotFound'
 

Protected Attributes

 $_messageTemplates
 
 $_files
 
- Protected Attributes inherited from Zend_Validate_File_Size
 $_messageTemplates
 
 $_messageVariables
 
 $_min
 
 $_max
 
 $_size
 
 $_useByteString = true
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_File_Size
 _getSize ()
 
 _setSize ($size)
 
 _toByteString ($size)
 
 _fromByteString ($size)
 
 _throw ($file, $errorType)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 35 of file FilesSize.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Sets validator options

Min limits the used diskspace for all files, when used with max=null it is the maximum filesize It also accepts an array with the keys 'min' and 'max'

Parameters
integer | array | Zend_Config$optionsOptions for this validator
Exceptions
Zend_Validate_Exception

Definition at line 69 of file FilesSize.php.

70  {
71  $this->_files = array();
72  $this->_setSize(0);
73 
74  if ($options instanceof Zend_Config) {
75  $options = $options->toArray();
76  } elseif (is_scalar($options)) {
77  $options = array('max' => $options);
78  } elseif (!is_array($options)) {
79  #require_once 'Zend/Validate/Exception.php';
80  throw new Zend_Validate_Exception('Invalid options to validator provided');
81  }
82 
83  if (1 < func_num_args()) {
84  $argv = func_get_args();
85  array_shift($argv);
86  $options['max'] = array_shift($argv);
87  if (!empty($argv)) {
88  $options['bytestring'] = array_shift($argv);
89  }
90  }
91 
92  parent::__construct($options);
93  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

Member Function Documentation

◆ isValid()

isValid (   $value,
  $file = null 
)

Defined by Zend_Validate_Interface

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).

Parameters
string | array$valueReal file to check for size
array$fileFile data from Zend_File_Transfer
Returns
boolean

Definition at line 105 of file FilesSize.php.

106  {
107  #require_once 'Zend/Loader.php';
108  if (is_string($value)) {
109  $value = array($value);
110  }
111 
112  $min = $this->getMin(true);
113  $max = $this->getMax(true);
114  $size = $this->_getSize();
115  foreach ($value as $files) {
116  // Is file readable ?
118  $this->_throw($file, self::NOT_READABLE);
119  continue;
120  }
121 
122  if (!isset($this->_files[$files])) {
123  $this->_files[$files] = $files;
124  } else {
125  // file already counted... do not count twice
126  continue;
127  }
128 
129  // limited to 2GB files
130  $size += @filesize($files);
131  $this->_size = $size;
132  if (($max !== null) && ($max < $size)) {
133  if ($this->useByteString()) {
134  $this->_max = $this->_toByteString($max);
135  $this->_size = $this->_toByteString($size);
136  $this->_throw($file, self::TOO_BIG);
137  $this->_max = $max;
138  $this->_size = $size;
139  } else {
140  $this->_throw($file, self::TOO_BIG);
141  }
142  }
143  }
144 
145  // Check that aggregate files are >= minimum size
146  if (($min !== null) && ($size < $min)) {
147  if ($this->useByteString()) {
148  $this->_min = $this->_toByteString($min);
149  $this->_size = $this->_toByteString($size);
150  $this->_throw($file, self::TOO_SMALL);
151  $this->_min = $min;
152  $this->_size = $size;
153  } else {
154  $this->_throw($file, self::TOO_SMALL);
155  }
156  }
157 
158  return empty($this->_messages);
159  }
getMax($raw=false)
Definition: Size.php:207
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16
getMin($raw=false)
Definition: Size.php:165
_throw($file, $errorType)
Definition: Size.php:392
foreach($appDirs as $dir) $files

Field Documentation

◆ $_files

$_files
protected

Definition at line 58 of file FilesSize.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
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",
)

Definition at line 47 of file FilesSize.php.

◆ NOT_READABLE

const NOT_READABLE = 'fileFilesSizeNotReadable'

Definition at line 42 of file FilesSize.php.

◆ TOO_BIG

const TOO_BIG = 'fileFilesSizeTooBig'

@const string Error constants

Definition at line 40 of file FilesSize.php.

◆ TOO_SMALL

const TOO_SMALL = 'fileFilesSizeTooSmall'

Definition at line 41 of file FilesSize.php.


The documentation for this class was generated from the following file: