Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Callback.php
Go to the documentation of this file.
1 <?php
33 {
37  protected $_class;
38 
42  protected $_function;
43 
47  protected $_method;
48 
52  protected $_type;
53 
57  protected $_types = array('function', 'static', 'instance');
58 
65  public function __construct($options = null)
66  {
67  if ((null !== $options) && is_array($options)) {
68  $this->setOptions($options);
69  }
70  }
71 
78  public function setOptions(array $options)
79  {
80  foreach ($options as $key => $value) {
81  $method = 'set' . ucfirst($key);
82  if (method_exists($this, $method)) {
83  $this->$method($value);
84  }
85  }
86  return $this;
87  }
88 
95  public function setClass($class)
96  {
97  if (is_object($class)) {
98  $class = get_class($class);
99  }
100  $this->_class = $class;
101  return $this;
102  }
103 
109  public function getClass()
110  {
111  return $this->_class;
112  }
113 
120  public function setFunction($function)
121  {
122  $this->_function = (string) $function;
123  $this->setType('function');
124  return $this;
125  }
126 
132  public function getFunction()
133  {
134  return $this->_function;
135  }
136 
143  public function setMethod($method)
144  {
145  $this->_method = $method;
146  return $this;
147  }
148 
154  public function getMethod()
155  {
156  return $this->_method;
157  }
158 
166  public function setType($type)
167  {
168  if (!in_array($type, $this->_types)) {
169  #require_once 'Zend/Server/Exception.php';
170  throw new Zend_Server_Exception('Invalid method callback type passed to ' . __CLASS__ . '::' . __METHOD__);
171  }
172  $this->_type = $type;
173  return $this;
174  }
175 
181  public function getType()
182  {
183  return $this->_type;
184  }
185 
191  public function toArray()
192  {
193  $type = $this->getType();
194  $array = array(
195  'type' => $type,
196  );
197  if ('function' == $type) {
198  $array['function'] = $this->getFunction();
199  } else {
200  $array['class'] = $this->getClass();
201  $array['method'] = $this->getMethod();
202  }
203  return $array;
204  }
205 }
setOptions(array $options)
Definition: Callback.php:78
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13
__construct($options=null)
Definition: Callback.php:65