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

Public Member Functions

 __construct ($options)
 
 getMin ()
 
 setMin ($min)
 
 getMax ()
 
 setMax ($max)
 
 addFile ($file)
 
 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_MANY = 'fileCountTooMany'
 
const TOO_FEW = 'fileCountTooFew'
 

Protected Member Functions

 _throw ($file, $errorType)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Protected Attributes

 $_messageTemplates
 
 $_messageVariables
 
 $_min
 
 $_max
 
 $_count
 
 $_files
 
- 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)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 35 of file Count.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Sets validator options

Min limits the file count, when used with max=null it is the maximum file count It also accepts an array with the keys 'min' and 'max'

If $options is a integer, it will be used as maximum file count As Array is accepts the following keys: 'min': Minimum filecount 'max': Maximum filecount

Parameters
integer | array | Zend_Config$optionsOptions for the adapter
Exceptions
Zend_Validate_Exception

Definition at line 106 of file Count.php.

107  {
108  if ($options instanceof Zend_Config) {
109  $options = $options->toArray();
110  } elseif (is_string($options) || is_numeric($options)) {
111  $options = array('max' => $options);
112  } elseif (!is_array($options)) {
113  #require_once 'Zend/Validate/Exception.php';
114  throw new Zend_Validate_Exception ('Invalid options to validator provided');
115  }
116 
117  if (1 < func_num_args()) {
118  $options['min'] = func_get_arg(0);
119  $options['max'] = func_get_arg(1);
120  }
121 
122  if (isset($options['min'])) {
123  $this->setMin($options);
124  }
125 
126  if (isset($options['max'])) {
127  $this->setMax($options);
128  }
129  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

Member Function Documentation

◆ _throw()

_throw (   $file,
  $errorType 
)
protected

Throws an error of the given type

Parameters
string$file
string$errorType
Returns
false

Definition at line 276 of file Count.php.

277  {
278  if ($file !== null) {
279  $this->_value = $file['name'];
280  }
281 
282  $this->_error($errorType);
283  return false;
284  }
_error($messageKey, $value=null)
Definition: Abstract.php:284

◆ addFile()

addFile (   $file)

Adds a file for validation

Parameters
string | array$file
Returns
$this

Definition at line 215 of file Count.php.

216  {
217  if (is_string($file)) {
218  $file = array($file);
219  }
220 
221  if (is_array($file)) {
222  foreach ($file as $name) {
223  if (!isset($this->_files[$name]) && !empty($name)) {
224  $this->_files[$name] = $name;
225  }
226  }
227  }
228 
229  return $this;
230  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getMax()

getMax ( )

Returns the maximum file count

Returns
integer

Definition at line 175 of file Count.php.

176  {
177  return $this->_max;
178  }

◆ getMin()

getMin ( )

Returns the minimum file count

Returns
integer

Definition at line 136 of file Count.php.

137  {
138  return $this->_min;
139  }

◆ isValid()

isValid (   $value,
  $file = null 
)

Defined by Zend_Validate_Interface

Returns true if and only if the file count of all checked files is at least min and not bigger than max (when max is not null). Attention: When checking with set min you must give all files with the first call, otherwise you will get an false.

Parameters
string | array$valueFilenames to check for count
array$fileFile data from Zend_File_Transfer
Returns
boolean

Definition at line 243 of file Count.php.

244  {
245  if (($file !== null) && !array_key_exists('destination', $file)) {
246  $file['destination'] = dirname($value);
247  }
248 
249  if (($file !== null) && array_key_exists('tmp_name', $file)) {
250  $value = $file['destination'] . DIRECTORY_SEPARATOR . $file['name'];
251  }
252 
253  if (($file === null) || !empty($file['tmp_name'])) {
254  $this->addFile($value);
255  }
256 
257  $this->_count = count($this->_files);
258  if (($this->_max !== null) && ($this->_count > $this->_max)) {
259  return $this->_throw($file, self::TOO_MANY);
260  }
261 
262  if (($this->_min !== null) && ($this->_count < $this->_min)) {
263  return $this->_throw($file, self::TOO_FEW);
264  }
265 
266  return true;
267  }
_throw($file, $errorType)
Definition: Count.php:276
$value
Definition: gender.phtml:16

◆ setMax()

setMax (   $max)

Sets the maximum file count

Parameters
integer | array$maxThe maximum file count
Returns
Zend_Validate_StringLength Provides a fluent interface
Exceptions
Zend_Validate_ExceptionWhen max is smaller than min

Definition at line 187 of file Count.php.

188  {
189  if (is_array($max) and isset($max['max'])) {
190  $max = $max['max'];
191  }
192 
193  if (!is_string($max) and !is_numeric($max)) {
194  #require_once 'Zend/Validate/Exception.php';
195  throw new Zend_Validate_Exception ('Invalid options to validator provided');
196  }
197 
198  $max = (integer) $max;
199  if (($this->_min !== null) && ($max < $this->_min)) {
200  #require_once 'Zend/Validate/Exception.php';
201  throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum file count, but "
202  . "$max < {$this->_min}");
203  }
204 
205  $this->_max = $max;
206  return $this;
207  }

◆ setMin()

setMin (   $min)

Sets the minimum file count

Parameters
integer | array$minThe minimum file count
Returns
Zend_Validate_File_Count Provides a fluent interface
Exceptions
Zend_Validate_ExceptionWhen min is greater than max

Definition at line 148 of file Count.php.

149  {
150  if (is_array($min) and isset($min['min'])) {
151  $min = $min['min'];
152  }
153 
154  if (!is_string($min) and !is_numeric($min)) {
155  #require_once 'Zend/Validate/Exception.php';
156  throw new Zend_Validate_Exception ('Invalid options to validator provided');
157  }
158 
159  $min = (integer) $min;
160  if (($this->_max !== null) && ($min > $this->_max)) {
161  #require_once 'Zend/Validate/Exception.php';
162  throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum file count, but $min >"
163  . " {$this->_max}");
164  }
165 
166  $this->_min = $min;
167  return $this;
168  }

Field Documentation

◆ $_count

$_count
protected

Definition at line 84 of file Count.php.

◆ $_files

$_files
protected

Definition at line 90 of file Count.php.

◆ $_max

$_max
protected

Definition at line 77 of file Count.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::TOO_MANY => "Too many files, maximum '%max%' are allowed but '%count%' are given",
self::TOO_FEW => "Too few files, minimum '%min%' are expected but '%count%' are given",
)

Definition at line 47 of file Count.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'min' => '_min',
'max' => '_max',
'count' => '_count'
)

Definition at line 55 of file Count.php.

◆ $_min

$_min
protected

Definition at line 68 of file Count.php.

◆ TOO_FEW

const TOO_FEW = 'fileCountTooFew'

Definition at line 41 of file Count.php.

◆ TOO_MANY

const TOO_MANY = 'fileCountTooMany'

#+ @const string Error constants

Definition at line 40 of file Count.php.


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