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

Public Member Functions

 __construct ($options=array())
 
 getMin ()
 
 setMin ($min)
 
 getMax ()
 
 setMax ($max)
 
 getEncoding ()
 
 setEncoding ($encoding=null)
 
 isValid ($value)
 
- 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 ()
 

Data Fields

const INVALID = 'stringLengthInvalid'
 
const TOO_SHORT = 'stringLengthTooShort'
 
const TOO_LONG = 'stringLengthTooLong'
 

Protected Attributes

 $_messageTemplates
 
 $_messageVariables
 
 $_min
 
 $_max
 
 $_encoding
 
- 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_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 33 of file StringLength.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = array())

Sets validator options

Parameters
integer | array | Zend_Config$options

Definition at line 84 of file StringLength.php.

85  {
86  if ($options instanceof Zend_Config) {
87  $options = $options->toArray();
88  } else if (!is_array($options)) {
89  $options = func_get_args();
90  $temp['min'] = array_shift($options);
91  if (!empty($options)) {
92  $temp['max'] = array_shift($options);
93  }
94 
95  if (!empty($options)) {
96  $temp['encoding'] = array_shift($options);
97  }
98 
99  $options = $temp;
100  }
101 
102  if (!array_key_exists('min', $options)) {
103  $options['min'] = 0;
104  }
105 
106  $this->setMin($options['min']);
107  if (array_key_exists('max', $options)) {
108  $this->setMax($options['max']);
109  }
110 
111  if (array_key_exists('encoding', $options)) {
112  $this->setEncoding($options['encoding']);
113  }
114  }
setEncoding($encoding=null)

Member Function Documentation

◆ getEncoding()

getEncoding ( )

Returns the actual encoding

Returns
string

Definition at line 187 of file StringLength.php.

188  {
189  return $this->_encoding;
190  }

◆ getMax()

getMax ( )

Returns the max option

Returns
integer|null

Definition at line 152 of file StringLength.php.

153  {
154  return $this->_max;
155  }

◆ getMin()

getMin ( )

Returns the min option

Returns
integer

Definition at line 121 of file StringLength.php.

122  {
123  return $this->_min;
124  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if the string length of $value is at least the min option and no greater than the max option (when the max option is not null).

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 239 of file StringLength.php.

240  {
241  if (!is_string($value)) {
242  $this->_error(self::INVALID);
243  return false;
244  }
245 
246  $this->_setValue($value);
247  if ($this->_encoding !== null) {
248  $length = iconv_strlen($value, $this->_encoding);
249  } else {
250  $length = iconv_strlen($value);
251  }
252 
253  if ($length < $this->_min) {
254  $this->_error(self::TOO_SHORT);
255  }
256 
257  if (null !== $this->_max && $this->_max < $length) {
258  $this->_error(self::TOO_LONG);
259  }
260 
261  if (count($this->_messages)) {
262  return false;
263  } else {
264  return true;
265  }
266  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16

◆ setEncoding()

setEncoding (   $encoding = null)

Sets a new encoding to use

Parameters
string$encoding
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_StringLength

Definition at line 199 of file StringLength.php.

200  {
201  if ($encoding !== null) {
202  $orig = PHP_VERSION_ID < 50600
203  ? iconv_get_encoding('internal_encoding')
204  : ini_get('default_charset');
205  if (PHP_VERSION_ID < 50600) {
206  if ($encoding) {
207  $result = iconv_set_encoding('internal_encoding', $encoding);
208  } else {
209  $result = false;
210  }
211  } else {
212  ini_set('default_charset', $encoding);
213  $result = ini_get('default_charset');
214  }
215  if ($result === false) {
216  #require_once 'Zend/Validate/Exception.php';
217  throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
218  }
219 
220  if (PHP_VERSION_ID < 50600) {
221  iconv_set_encoding('internal_encoding', $orig);
222  } else {
223  ini_set('default_charset', $orig);
224  }
225  }
226  $this->_encoding = $encoding;
227  return $this;
228  }
ini_set($varName, $newValue)

◆ setMax()

setMax (   $max)

Sets the max option

Parameters
integer | null$max
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_StringLength Provides a fluent interface
See also
Zend_Validate_Exception

Definition at line 164 of file StringLength.php.

165  {
166  if (null === $max) {
167  $this->_max = null;
168  } else if ($max < $this->_min) {
172  #require_once 'Zend/Validate/Exception.php';
173  throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum length, but "
174  . "$max < $this->_min");
175  } else {
176  $this->_max = (integer) $max;
177  }
178 
179  return $this;
180  }

◆ setMin()

setMin (   $min)

Sets the min option

Parameters
integer$min
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_StringLength Provides a fluent interface
See also
Zend_Validate_Exception

Definition at line 133 of file StringLength.php.

134  {
135  if (null !== $this->_max && $min > $this->_max) {
139  #require_once 'Zend/Validate/Exception.php';
140  throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum length, but $min >"
141  . " $this->_max");
142  }
143  $this->_min = max(0, (integer) $min);
144  return $this;
145  }

Field Documentation

◆ $_encoding

$_encoding
protected

Definition at line 77 of file StringLength.php.

◆ $_max

$_max
protected

Definition at line 70 of file StringLength.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INVALID => "Invalid type given. String expected",
self::TOO_SHORT => "'%value%' is less than %min% characters long",
self::TOO_LONG => "'%value%' is more than %max% characters long",
)

Definition at line 42 of file StringLength.php.

◆ $_messageVariables

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

Definition at line 51 of file StringLength.php.

◆ $_min

$_min
protected

Definition at line 61 of file StringLength.php.

◆ INVALID

const INVALID = 'stringLengthInvalid'

Definition at line 35 of file StringLength.php.

◆ TOO_LONG

const TOO_LONG = 'stringLengthTooLong'

Definition at line 37 of file StringLength.php.

◆ TOO_SHORT

const TOO_SHORT = 'stringLengthTooShort'

Definition at line 36 of file StringLength.php.


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