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_ImageSize Class Reference
Inheritance diagram for Zend_Validate_File_ImageSize:
Zend_Validate_Abstract Zend_Validate_Interface ImageSize

Public Member Functions

 __construct ($options)
 
 getImageMin ()
 
 getImageMax ()
 
 getImageWidth ()
 
 getImageHeight ()
 
 setImageMin ($options)
 
 setImageMax ($options)
 
 setImageWidth ($options)
 
 setImageHeight ($options)
 
 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 WIDTH_TOO_BIG = 'fileImageSizeWidthTooBig'
 
const WIDTH_TOO_SMALL = 'fileImageSizeWidthTooSmall'
 
const HEIGHT_TOO_BIG = 'fileImageSizeHeightTooBig'
 
const HEIGHT_TOO_SMALL = 'fileImageSizeHeightTooSmall'
 
const NOT_DETECTED = 'fileImageSizeNotDetected'
 
const NOT_READABLE = 'fileImageSizeNotReadable'
 

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
 
 $_minwidth
 
 $_maxwidth
 
 $_minheight
 
 $_maxheight
 
 $_width
 
 $_height
 
- 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 ImageSize.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Sets validator options

Accepts the following option keys:

  • minheight
  • minwidth
  • maxheight
  • maxwidth
Parameters
Zend_Config | array$options
Exceptions
Zend_Validate_Exception

Definition at line 125 of file ImageSize.php.

126  {
127  if ($options instanceof Zend_Config) {
128  $options = $options->toArray();
129  } elseif (1 < func_num_args()) {
130  if (!is_array($options)) {
131  $options = array('minwidth' => $options);
132  }
133  $argv = func_get_args();
134  array_shift($argv);
135  $options['minheight'] = array_shift($argv);
136  if (!empty($argv)) {
137  $options['maxwidth'] = array_shift($argv);
138  if (!empty($argv)) {
139  $options['maxheight'] = array_shift($argv);
140  }
141  }
142  } else if (!is_array($options)) {
143  #require_once 'Zend/Validate/Exception.php';
144  throw new Zend_Validate_Exception ('Invalid options to validator provided');
145  }
146 
147  if (isset($options['minheight']) || isset($options['minwidth'])) {
148  $this->setImageMin($options);
149  }
150 
151  if (isset($options['maxheight']) || isset($options['maxwidth'])) {
152  $this->setImageMax($options);
153  }
154  }
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 351 of file ImageSize.php.

352  {
353  if ($file !== null) {
354  $this->_value = $file['name'];
355  }
356 
357  $this->_error($errorType);
358  return false;
359  }
_error($messageKey, $value=null)
Definition: Abstract.php:284

◆ getImageHeight()

getImageHeight ( )

Returns the set image height sizes

Returns
array

Definition at line 191 of file ImageSize.php.

192  {
193  return array('minheight' => $this->_minheight, 'maxheight' => $this->_maxheight);
194  }

◆ getImageMax()

getImageMax ( )

Returns the set maximum image sizes

Returns
array

Definition at line 171 of file ImageSize.php.

172  {
173  return array('maxwidth' => $this->_maxwidth, 'maxheight' => $this->_maxheight);
174  }

◆ getImageMin()

getImageMin ( )

Returns the set minimum image sizes

Returns
array

Definition at line 161 of file ImageSize.php.

162  {
163  return array('minwidth' => $this->_minwidth, 'minheight' => $this->_minheight);
164  }

◆ getImageWidth()

getImageWidth ( )

Returns the set image width sizes

Returns
array

Definition at line 181 of file ImageSize.php.

182  {
183  return array('minwidth' => $this->_minwidth, 'maxwidth' => $this->_maxwidth);
184  }

◆ isValid()

isValid (   $value,
  $file = null 
)

Defined by Zend_Validate_Interface

Returns true if and only if the imagesize of $value is at least min and not bigger than max

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

Definition at line 308 of file ImageSize.php.

309  {
310  // Is file readable ?
311  #require_once 'Zend/Loader.php';
313  return $this->_throw($file, self::NOT_READABLE);
314  }
315 
316  $size = @getimagesize($value);
317  $this->_setValue($file);
318 
319  if (empty($size) or ($size[0] === 0) or ($size[1] === 0)) {
320  return $this->_throw($file, self::NOT_DETECTED);
321  }
322 
323  $this->_width = $size[0];
324  $this->_height = $size[1];
325  if ($this->_width < $this->_minwidth) {
326  $this->_throw($file, self::WIDTH_TOO_SMALL);
327  }
328 
329  if (($this->_maxwidth !== null) and ($this->_maxwidth < $this->_width)) {
330  $this->_throw($file, self::WIDTH_TOO_BIG);
331  }
332 
333  if ($this->_height < $this->_minheight) {
334  $this->_throw($file, self::HEIGHT_TOO_SMALL);
335  }
336 
337  if (($this->_maxheight !== null) and ($this->_maxheight < $this->_height)) {
338  $this->_throw($file, self::HEIGHT_TOO_BIG);
339  }
340 
341  return empty($this->_messages);
342  }
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16
_throw($file, $errorType)
Definition: ImageSize.php:351

◆ setImageHeight()

setImageHeight (   $options)

Sets the mimimum and maximum image height

Parameters
array$optionsThe image height dimensions
Returns
Zend_Validate_File_ImageSize Provides a fluent interface

Definition at line 290 of file ImageSize.php.

291  {
292  $this->setImageMin($options);
293  $this->setImageMax($options);
294 
295  return $this;
296  }

◆ setImageMax()

setImageMax (   $options)

Sets the maximum image size

Parameters
array$optionsThe maximum image dimensions
Exceptions
Zend_Validate_ExceptionWhen maxwidth is smaller than minwidth
Zend_Validate_ExceptionWhen maxheight is smaller than minheight
Returns
Zend_Validate_StringLength Provides a fluent interface

Definition at line 241 of file ImageSize.php.

242  {
243  if (isset($options['maxwidth'])) {
244  if (($this->_minwidth !== null) and ($options['maxwidth'] < $this->_minwidth)) {
245  #require_once 'Zend/Validate/Exception.php';
246  throw new Zend_Validate_Exception("The maximum image width must be greater than or equal to the "
247  . "minimum image width, but {$options['maxwidth']} < {$this->_minwidth}");
248  }
249  }
250 
251  if (isset($options['maxheight'])) {
252  if (($this->_minheight !== null) and ($options['maxheight'] < $this->_minheight)) {
253  #require_once 'Zend/Validate/Exception.php';
254  throw new Zend_Validate_Exception("The maximum image height must be greater than or equal to the "
255  . "minimum image height, but {$options['maxheight']} < {$this->_minwidth}");
256  }
257  }
258 
259  if (isset($options['maxwidth'])) {
260  $this->_maxwidth = (int) $options['maxwidth'];
261  }
262 
263  if (isset($options['maxheight'])) {
264  $this->_maxheight = (int) $options['maxheight'];
265  }
266 
267  return $this;
268  }

◆ setImageMin()

setImageMin (   $options)

Sets the minimum image size

Parameters
array$optionsThe minimum image dimensions
Exceptions
Zend_Validate_ExceptionWhen minwidth is greater than maxwidth
Zend_Validate_ExceptionWhen minheight is greater than maxheight
Returns
Zend_Validate_File_ImageSize Provides a fluent interface

Definition at line 204 of file ImageSize.php.

205  {
206  if (isset($options['minwidth'])) {
207  if (($this->_maxwidth !== null) and ($options['minwidth'] > $this->_maxwidth)) {
208  #require_once 'Zend/Validate/Exception.php';
209  throw new Zend_Validate_Exception("The minimum image width must be less than or equal to the "
210  . " maximum image width, but {$options['minwidth']} > {$this->_maxwidth}");
211  }
212  }
213 
214  if (isset($options['maxheight'])) {
215  if (($this->_maxheight !== null) and ($options['minheight'] > $this->_maxheight)) {
216  #require_once 'Zend/Validate/Exception.php';
217  throw new Zend_Validate_Exception("The minimum image height must be less than or equal to the "
218  . " maximum image height, but {$options['minheight']} > {$this->_maxheight}");
219  }
220  }
221 
222  if (isset($options['minwidth'])) {
223  $this->_minwidth = (int) $options['minwidth'];
224  }
225 
226  if (isset($options['minheight'])) {
227  $this->_minheight = (int) $options['minheight'];
228  }
229 
230  return $this;
231  }

◆ setImageWidth()

setImageWidth (   $options)

Sets the mimimum and maximum image width

Parameters
array$optionsThe image width dimensions
Returns
Zend_Validate_File_ImageSize Provides a fluent interface

Definition at line 276 of file ImageSize.php.

277  {
278  $this->setImageMin($options);
279  $this->setImageMax($options);
280 
281  return $this;
282  }

Field Documentation

◆ $_height

$_height
protected

Definition at line 111 of file ImageSize.php.

◆ $_maxheight

$_maxheight
protected

Definition at line 97 of file ImageSize.php.

◆ $_maxwidth

$_maxwidth
protected

Definition at line 83 of file ImageSize.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::WIDTH_TOO_BIG => "Maximum allowed width for image '%value%' should be '%maxwidth%' but '%width%' detected",
self::WIDTH_TOO_SMALL => "Minimum expected width for image '%value%' should be '%minwidth%' but '%width%' detected",
self::HEIGHT_TOO_BIG => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected",
self::HEIGHT_TOO_SMALL => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected",
self::NOT_DETECTED => "The size of image '%value%' could not be detected",
self::NOT_READABLE => "File '%value%' is not readable or does not exist",
)

Definition at line 50 of file ImageSize.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'minwidth' => '_minwidth',
'maxwidth' => '_maxwidth',
'minheight' => '_minheight',
'maxheight' => '_maxheight',
'width' => '_width',
'height' => '_height'
)

Definition at line 62 of file ImageSize.php.

◆ $_minheight

$_minheight
protected

Definition at line 90 of file ImageSize.php.

◆ $_minwidth

$_minwidth
protected

Definition at line 76 of file ImageSize.php.

◆ $_width

$_width
protected

Definition at line 104 of file ImageSize.php.

◆ HEIGHT_TOO_BIG

const HEIGHT_TOO_BIG = 'fileImageSizeHeightTooBig'

Definition at line 42 of file ImageSize.php.

◆ HEIGHT_TOO_SMALL

const HEIGHT_TOO_SMALL = 'fileImageSizeHeightTooSmall'

Definition at line 43 of file ImageSize.php.

◆ NOT_DETECTED

const NOT_DETECTED = 'fileImageSizeNotDetected'

Definition at line 44 of file ImageSize.php.

◆ NOT_READABLE

const NOT_READABLE = 'fileImageSizeNotReadable'

Definition at line 45 of file ImageSize.php.

◆ WIDTH_TOO_BIG

const WIDTH_TOO_BIG = 'fileImageSizeWidthTooBig'

@const string Error constants

Definition at line 40 of file ImageSize.php.

◆ WIDTH_TOO_SMALL

const WIDTH_TOO_SMALL = 'fileImageSizeWidthTooSmall'

Definition at line 41 of file ImageSize.php.


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