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

Public Member Functions

 __construct ($callback=null)
 
 getCallback ()
 
 setCallback ($callback)
 
 getOptions ()
 
 setOptions ($options)
 
 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_CALLBACK = 'callbackInvalid'
 
const INVALID_VALUE = 'callbackValue'
 

Protected Attributes

 $_messageTemplates
 
 $_callback = null
 
 $_options = array()
 
- 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 Callback.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $callback = null)

Sets validator options

Parameters
mixed$callback
Exceptions
Zend_Validate_Exception

Definition at line 75 of file Callback.php.

76  {
77  if (is_callable($callback)) {
78  $this->setCallback($callback);
79  } elseif (is_array($callback)) {
80  if (isset($callback['callback'])) {
81  $this->setCallback($callback['callback']);
82  }
83  if (isset($callback['options'])) {
84  $this->setOptions($callback['options']);
85  }
86  }
87 
88  if (null === ($initializedCallack = $this->getCallback())) {
89  #require_once 'Zend/Validate/Exception.php';
90  throw new Zend_Validate_Exception('No callback registered');
91  }
92  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setCallback($callback)
Definition: Callback.php:111

Member Function Documentation

◆ getCallback()

getCallback ( )

Returns the set callback

Returns
mixed

Definition at line 99 of file Callback.php.

100  {
101  return $this->_callback;
102  }

◆ getOptions()

getOptions ( )

Returns the set options for the callback

Returns
mixed

Definition at line 126 of file Callback.php.

127  {
128  return $this->_options;
129  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if the set callback returns for the provided $value

Parameters
mixed$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 152 of file Callback.php.

153  {
154  $this->_setValue($value);
155 
156  $options = $this->getOptions();
157  $callback = $this->getCallback();
158  $args = func_get_args();
159  $options = array_merge($args, $options);
160 
161  try {
162  if (!call_user_func_array($callback, $options)) {
163  $this->_error(self::INVALID_VALUE);
164  return false;
165  }
166  } catch (Exception $e) {
167  $this->_error(self::INVALID_CALLBACK);
168  return false;
169  }
170 
171  return true;
172  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16

◆ setCallback()

setCallback (   $callback)

Sets the callback

Parameters
string | array$callback
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_Callback Provides a fluent interface

Definition at line 111 of file Callback.php.

112  {
113  if (!is_callable($callback)) {
114  #require_once 'Zend/Validate/Exception.php';
115  throw new Zend_Validate_Exception('Invalid callback given');
116  }
117  $this->_callback = $callback;
118  return $this;
119  }

◆ setOptions()

setOptions (   $options)

Sets options for the callback

Parameters
mixed$options
Returns
Zend_Validate_Callback Provides a fluent interface

Definition at line 137 of file Callback.php.

138  {
139  $this->_options = (array) $options;
140  return $this;
141  }

Field Documentation

◆ $_callback

$_callback = null
protected

Definition at line 60 of file Callback.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INVALID_VALUE => "'%value%' is not valid",
self::INVALID_CALLBACK => "An exception has been raised within the callback",
)

Definition at line 50 of file Callback.php.

◆ $_options

$_options = array()
protected

Definition at line 67 of file Callback.php.

◆ INVALID_CALLBACK

const INVALID_CALLBACK = 'callbackInvalid'

Invalid callback

Definition at line 38 of file Callback.php.

◆ INVALID_VALUE

const INVALID_VALUE = 'callbackValue'

Invalid value

Definition at line 43 of file Callback.php.


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