Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Filter_Callback Class Reference
Inheritance diagram for Zend_Filter_Callback:
Zend_Filter_Interface

Public Member Functions

 __construct ($options)
 
 getCallback ()
 
 setCallback ($callback, $options=null)
 
 getOptions ()
 
 setOptions ($options)
 
 filter ($value)
 

Protected Attributes

 $_callback = null
 
 $_options = null
 

Detailed Description

Definition at line 33 of file Callback.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Constructor

Parameters
string | array$callbackCallback in a call_user_func format
mixed$options(Optional) Default options for this filter

Definition at line 55 of file Callback.php.

56  {
57  if ($options instanceof Zend_Config) {
58  $options = $options->toArray();
59  } else if (!is_array($options) || !array_key_exists('callback', $options)) {
60  $options = func_get_args();
61  $temp['callback'] = array_shift($options);
62  if (!empty($options)) {
63  $temp['options'] = array_shift($options);
64  }
65 
66  $options = $temp;
67  }
68 
69  if (!array_key_exists('callback', $options)) {
70  #require_once 'Zend/Filter/Exception.php';
71  throw new Zend_Filter_Exception('Missing callback to use');
72  }
73 
74  $this->setCallback($options['callback']);
75  if (array_key_exists('options', $options)) {
76  $this->setOptions($options['options']);
77  }
78  }
setCallback($callback, $options=null)
Definition: Callback.php:96
setOptions($options)
Definition: Callback.php:124

Member Function Documentation

◆ filter()

filter (   $value)

Calls the filter per callback

Parameters
mixed$valueOptions for the set callback
Returns
mixed Result from the filter which was callbacked

Implements Zend_Filter_Interface.

Definition at line 136 of file Callback.php.

137  {
138  $options = array();
139 
140  if ($this->_options !== null) {
141  if (!is_array($this->_options)) {
142  $options = array($this->_options);
143  } else {
145  }
146  }
147 
148  array_unshift($options, $value);
149 
150  return call_user_func_array($this->_callback, $options);
151  }
$value
Definition: gender.phtml:16

◆ getCallback()

getCallback ( )

Returns the set callback

Returns
string|array Set callback

Definition at line 85 of file Callback.php.

86  {
87  return $this->_callback;
88  }

◆ getOptions()

getOptions ( )

Returns the set default options

Returns
mixed

Definition at line 113 of file Callback.php.

114  {
115  return $this->_options;
116  }

◆ setCallback()

setCallback (   $callback,
  $options = null 
)

Sets a new callback for this filter

Parameters
unknown_type$callback
Returns
unknown

Definition at line 96 of file Callback.php.

97  {
98  if (!is_callable($callback)) {
99  #require_once 'Zend/Filter/Exception.php';
100  throw new Zend_Filter_Exception('Callback can not be accessed');
101  }
102 
103  $this->_callback = $callback;
104  $this->setOptions($options);
105  return $this;
106  }
setOptions($options)
Definition: Callback.php:124

◆ setOptions()

setOptions (   $options)

Sets new default options to the callback filter

Parameters
mixed$optionsDefault options to set
Returns
Zend_Filter_Callback

Definition at line 124 of file Callback.php.

125  {
126  $this->_options = $options;
127  return $this;
128  }

Field Documentation

◆ $_callback

$_callback = null
protected

Definition at line 40 of file Callback.php.

◆ $_options

$_options = null
protected

Definition at line 47 of file Callback.php.


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