Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Zend_Validate_Abstract Class Reference
Inheritance diagram for Zend_Validate_Abstract:
Zend_Validate_Interface Validator Validator AvailablePath NotProtectedExtension Zend_Validate_Alnum Zend_Validate_Alpha Zend_Validate_Barcode Zend_Validate_Between Zend_Validate_Callback Zend_Validate_Ccnum Zend_Validate_CreditCard Zend_Validate_Date Zend_Validate_Db_Abstract Zend_Validate_Digits Zend_Validate_EmailAddress Zend_Validate_File_Count Zend_Validate_File_Exists Zend_Validate_File_Extension Zend_Validate_File_Hash Zend_Validate_File_ImageSize Zend_Validate_File_MimeType Zend_Validate_File_Size Zend_Validate_File_Upload Zend_Validate_Float Zend_Validate_GreaterThan Zend_Validate_Hex Zend_Validate_Hostname Zend_Validate_Iban Zend_Validate_Identical Zend_Validate_InArray Zend_Validate_Int Zend_Validate_Ip Zend_Validate_Isbn Zend_Validate_LessThan Zend_Validate_NotEmpty Zend_Validate_PostCode Zend_Validate_Regex Zend_Validate_Sitemap_Changefreq Zend_Validate_Sitemap_Lastmod Zend_Validate_Sitemap_Loc Zend_Validate_Sitemap_Priority Zend_Validate_StringLength

Public Member Functions

 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)
 

Static Public Member Functions

static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 

Protected Member Functions

 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Protected Attributes

 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Static Protected Attributes

static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 33 of file Abstract.php.

Member Function Documentation

◆ __get()

__get (   $property)

Magic function returns the value of the requested property, if and only if it is the value or a message variable.

Parameters
string$property
Returns
mixed
Exceptions
Zend_Validate_Exception
See also
Zend_Validate_Exception

Definition at line 183 of file Abstract.php.

184  {
185  if ($property == 'value') {
186  return $this->_value;
187  }
188  if (array_key_exists($property, $this->_messageVariables)) {
189  return $this->{$this->_messageVariables[$property]};
190  }
194  #require_once 'Zend/Validate/Exception.php';
195  throw new Zend_Validate_Exception("No property exists by the name '$property'");
196  }

◆ _createMessage()

_createMessage (   $messageKey,
  $value 
)
protected

Constructs and returns a validation failure message with the given message key and value.

Returns null if and only if $messageKey does not correspond to an existing template.

If a translator is available and a translation exists for $messageKey, the translation will be used.

Parameters
string$messageKey
string$value
Returns
string

Definition at line 210 of file Abstract.php.

211  {
212  if (!isset($this->_messageTemplates[$messageKey])) {
213  return null;
214  }
215 
216  $message = $this->_messageTemplates[$messageKey];
217 
218  if (null !== ($translator = $this->getTranslator())) {
219  if ($translator->isTranslated($messageKey)) {
220  $message = $translator->translate($messageKey);
221  } else {
222  $message = $translator->translate($message);
223  }
224  }
225 
226  if (is_object($value)) {
227  if (!in_array('__toString', get_class_methods($value))) {
228  $value = get_class($value) . ' object';
229  } else {
230  $value = $value->__toString();
231  }
232  } elseif (is_array($value)) {
233  $value = $this->_implodeRecursive($value);
234  } else {
235  $value = implode((array) $value);
236  }
237 
238  if ($this->getObscureValue()) {
239  $value = str_repeat('*', strlen($value));
240  }
241 
242  $message = str_replace('%value%', $value, $message);
243  foreach ($this->_messageVariables as $ident => $property) {
244  $message = str_replace(
245  "%$ident%",
246  implode(' ', (array) $this->$property),
247  $message
248  );
249  }
250 
251  $length = self::getMessageLength();
252  if (($length > -1) && (strlen($message) > $length)) {
253  $message = substr($message, 0, (self::getMessageLength() - 3)) . '...';
254  }
255 
256  return $message;
257  }
_implodeRecursive(array $pieces)
Definition: Abstract.php:265
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$message
static getMessageLength()
Definition: Abstract.php:469
$value
Definition: gender.phtml:16

◆ _error()

_error (   $messageKey,
  $value = null 
)
protected
Parameters
string$messageKey
string$valueOPTIONAL
Returns
void

Definition at line 284 of file Abstract.php.

285  {
286  if ($messageKey === null) {
287  $keys = array_keys($this->_messageTemplates);
288  $messageKey = current($keys);
289  }
290  if ($value === null) {
292  }
293  $this->_errors[] = $messageKey;
294  $this->_messages[$messageKey] = $this->_createMessage($messageKey, $value);
295  }
$value
Definition: gender.phtml:16
_createMessage($messageKey, $value)
Definition: Abstract.php:210

◆ _implodeRecursive()

_implodeRecursive ( array  $pieces)
protected

Joins elements of a multidimensional array

Parameters
array$pieces
Returns
string

Definition at line 265 of file Abstract.php.

266  {
267  $values = array();
268  foreach ($pieces as $item) {
269  if (is_array($item)) {
270  $values[] = $this->_implodeRecursive($item);
271  } else {
272  $values[] = $item;
273  }
274  }
275 
276  return implode(', ', $values);
277  }
_implodeRecursive(array $pieces)
Definition: Abstract.php:265
$values
Definition: options.phtml:88

◆ _setValue()

_setValue (   $value)
protected

Sets the value to be validated and clears the messages and errors arrays

Parameters
mixed$value
Returns
void

Definition at line 303 of file Abstract.php.

304  {
305  $this->_value = $value;
306  $this->_messages = array();
307  $this->_errors = array();
308  }
$value
Definition: gender.phtml:16

◆ getDefaultTranslator()

static getDefaultTranslator ( )
static

Get default translation object for all validate objects

Returns
Zend_Translate_Adapter|null

Definition at line 415 of file Abstract.php.

416  {
417  if (null === self::$_defaultTranslator) {
418  #require_once 'Zend/Registry.php';
419  if (Zend_Registry::isRegistered('Zend_Translate')) {
420  $translator = Zend_Registry::get('Zend_Translate');
421  if ($translator instanceof Zend_Translate_Adapter) {
422  return $translator;
423  } elseif ($translator instanceof Zend_Translate) {
424  return $translator->getAdapter();
425  }
426  }
427  }
428 
430  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static isRegistered($index)
Definition: Registry.php:178
static $_defaultTranslator
Definition: Abstract.php:88
static get($index)
Definition: Registry.php:141

◆ getErrors()

getErrors ( )

Returns array of validation failure message codes

Returns
array
Deprecated:
Since 1.5.0

Definition at line 316 of file Abstract.php.

317  {
318  return $this->_errors;
319  }

◆ getMessageLength()

static getMessageLength ( )
static

Returns the maximum allowed message length

Returns
integer

Definition at line 469 of file Abstract.php.

470  {
471  return self::$_messageLength;
472  }

◆ getMessages()

getMessages ( )

Returns array of validation failure messages

Returns
array

Implements Zend_Validate_Interface.

Definition at line 108 of file Abstract.php.

109  {
110  return $this->_messages;
111  }

◆ getMessageTemplates()

getMessageTemplates ( )

Returns the message templates from the validator

Returns
array

Definition at line 128 of file Abstract.php.

129  {
131  }

◆ getMessageVariables()

getMessageVariables ( )

Returns an array of the names of variables that are used in constructing validation failure messages

Returns
array

Definition at line 118 of file Abstract.php.

119  {
120  return array_keys($this->_messageVariables);
121  }

◆ getObscureValue()

getObscureValue ( )

Retrieve flag indicating whether or not value should be obfuscated in messages

Returns
bool

Definition at line 339 of file Abstract.php.

340  {
341  return $this->_obscureValue;
342  }

◆ getTranslator()

getTranslator ( )

Return translation object

Returns
Zend_Translate_Adapter|null

Definition at line 369 of file Abstract.php.

370  {
371  if ($this->translatorIsDisabled()) {
372  return null;
373  }
374 
375  if (null === $this->_translator) {
377  }
378 
379  return $this->_translator;
380  }
static getDefaultTranslator()
Definition: Abstract.php:415

◆ hasDefaultTranslator()

static hasDefaultTranslator ( )
static

Is there a default translation object set?

Returns
boolean

Definition at line 437 of file Abstract.php.

438  {
439  return (bool)self::$_defaultTranslator;
440  }
static $_defaultTranslator
Definition: Abstract.php:88

◆ hasTranslator()

hasTranslator ( )

Does this validator have its own specific translator?

Returns
bool

Definition at line 387 of file Abstract.php.

388  {
389  return (bool)$this->_translator;
390  }

◆ setDefaultTranslator()

static setDefaultTranslator (   $translator = null)
static

Set default translation object for all validate objects

Parameters
Zend_Translate | Zend_Translate_Adapter | null$translator
Exceptions
Zend_Validate_Exception

Definition at line 398 of file Abstract.php.

399  {
400  if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
401  self::$_defaultTranslator = $translator;
402  } elseif ($translator instanceof Zend_Translate) {
403  self::$_defaultTranslator = $translator->getAdapter();
404  } else {
405  #require_once 'Zend/Validate/Exception.php';
406  throw new Zend_Validate_Exception('Invalid translator specified');
407  }
408  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ setDisableTranslator()

setDisableTranslator (   $flag)

Indicate whether or not translation should be disabled

Parameters
bool$flag
Returns
Zend_Validate_Abstract

Definition at line 448 of file Abstract.php.

449  {
450  $this->_translatorDisabled = (bool) $flag;
451  return $this;
452  }

◆ setMessage()

setMessage (   $messageString,
  $messageKey = null 
)

Sets the validation failure message template for a particular key

Parameters
string$messageString
string$messageKeyOPTIONAL
Returns
Zend_Validate_Abstract Provides a fluent interface
Exceptions
Zend_Validate_Exception

Definition at line 141 of file Abstract.php.

142  {
143  if ($messageKey === null) {
144  $keys = array_keys($this->_messageTemplates);
145  foreach($keys as $key) {
146  $this->setMessage($messageString, $key);
147  }
148  return $this;
149  }
150 
151  if (!isset($this->_messageTemplates[$messageKey])) {
152  #require_once 'Zend/Validate/Exception.php';
153  throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
154  }
155 
156  $this->_messageTemplates[$messageKey] = $messageString;
157  return $this;
158  }
setMessage($messageString, $messageKey=null)
Definition: Abstract.php:141

◆ setMessageLength()

static setMessageLength (   $length = -1)
static

Sets the maximum allowed message length

Parameters
integer$length

Definition at line 479 of file Abstract.php.

480  {
481  self::$_messageLength = $length;
482  }

◆ setMessages()

setMessages ( array  $messages)

Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.

Parameters
array$messages
Returns
Zend_Validate_Abstract

Definition at line 167 of file Abstract.php.

168  {
169  foreach ($messages as $key => $message) {
170  $this->setMessage($message, $key);
171  }
172  return $this;
173  }
$message
setMessage($messageString, $messageKey=null)
Definition: Abstract.php:141

◆ setObscureValue()

setObscureValue (   $flag)

Set flag indicating whether or not value should be obfuscated in messages

Parameters
bool$flag
Returns
Zend_Validate_Abstract

Definition at line 327 of file Abstract.php.

328  {
329  $this->_obscureValue = (bool) $flag;
330  return $this;
331  }

◆ setTranslator()

setTranslator (   $translator = null)

Set translation object

Parameters
Zend_Translate | Zend_Translate_Adapter | null$translator
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_Abstract

Definition at line 351 of file Abstract.php.

352  {
353  if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
354  $this->_translator = $translator;
355  } elseif ($translator instanceof Zend_Translate) {
356  $this->_translator = $translator->getAdapter();
357  } else {
358  #require_once 'Zend/Validate/Exception.php';
359  throw new Zend_Validate_Exception('Invalid translator specified');
360  }
361  return $this;
362  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ translatorIsDisabled()

translatorIsDisabled ( )

Is translation disabled?

Returns
bool

Definition at line 459 of file Abstract.php.

460  {
462  }

Field Documentation

◆ $_defaultTranslator

$_defaultTranslator
staticprotected

Definition at line 88 of file Abstract.php.

◆ $_errors

$_errors = array()
protected

Definition at line 76 of file Abstract.php.

◆ $_messageLength

$_messageLength = -1
staticprotected

Definition at line 101 of file Abstract.php.

◆ $_messages

$_messages = array()
protected

Definition at line 61 of file Abstract.php.

◆ $_messageTemplates

$_messageTemplates = array()
protected

Definition at line 54 of file Abstract.php.

◆ $_messageVariables

$_messageVariables = array()
protected

Definition at line 47 of file Abstract.php.

◆ $_obscureValue

$_obscureValue = false
protected

Definition at line 68 of file Abstract.php.

◆ $_translator

$_translator
protected

Definition at line 82 of file Abstract.php.

◆ $_translatorDisabled

$_translatorDisabled = false
protected

Definition at line 94 of file Abstract.php.

◆ $_value

$_value
protected

Definition at line 40 of file Abstract.php.


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