Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Abstract.php
Go to the documentation of this file.
1 <?php
22 #require_once 'Zend/Server/Interface.php';
23 
27 #require_once 'Zend/Server/Definition.php';
28 
32 #require_once 'Zend/Server/Method/Definition.php';
33 
37 #require_once 'Zend/Server/Method/Callback.php';
38 
42 #require_once 'Zend/Server/Method/Prototype.php';
43 
47 #require_once 'Zend/Server/Method/Parameter.php';
48 
59 {
64  protected static $magic_methods = array(
65  '__call',
66  '__clone',
67  '__construct',
68  '__destruct',
69  '__get',
70  '__isset',
71  '__set',
72  '__set_state',
73  '__sleep',
74  '__tostring',
75  '__unset',
76  '__wakeup',
77  );
78 
82  protected $_overwriteExistingMethods = false;
83 
87  protected $_table;
88 
96  public function __construct()
97  {
98  $this->_table = new Zend_Server_Definition();
99  $this->_table->setOverwriteExistingMethods($this->_overwriteExistingMethods);
100  }
101 
109  public function getFunctions()
110  {
111  return $this->_table;
112  }
113 
124  public static function lowerCase(&$value, &$key)
125  {
126  trigger_error(__CLASS__ . '::' . __METHOD__ . '() is deprecated and will be removed in a future version', E_USER_NOTICE);
127  return $value = strtolower($value);
128  }
129 
137  {
138  $callback = new Zend_Server_Method_Callback();
139  if ($reflection instanceof Zend_Server_Reflection_Method) {
140  $callback->setType($reflection->isStatic() ? 'static' : 'instance')
141  ->setClass($reflection->getDeclaringClass()->getName())
142  ->setMethod($reflection->getName());
143  } elseif ($reflection instanceof Zend_Server_Reflection_Function) {
144  $callback->setType('function')
145  ->setFunction($reflection->getName());
146  }
147  return $callback;
148  }
149 
158  protected function _buildSignature(Zend_Server_Reflection_Function_Abstract $reflection, $class = null)
159  {
160  $ns = $reflection->getNamespace();
161  $name = $reflection->getName();
162  $method = empty($ns) ? $name : $ns . '.' . $name;
163 
164  if (!$this->_overwriteExistingMethods && $this->_table->hasMethod($method)) {
165  #require_once 'Zend/Server/Exception.php';
166  throw new Zend_Server_Exception('Duplicate method registered: ' . $method);
167  }
168 
169  $definition = new Zend_Server_Method_Definition();
170  $definition->setName($method)
171  ->setCallback($this->_buildCallback($reflection))
172  ->setMethodHelp($reflection->getDescription())
173  ->setInvokeArguments($reflection->getInvokeArguments());
174 
175  foreach ($reflection->getPrototypes() as $proto) {
176  $prototype = new Zend_Server_Method_Prototype();
177  $prototype->setReturnType($this->_fixType($proto->getReturnType()));
178  foreach ($proto->getParameters() as $parameter) {
179  $param = new Zend_Server_Method_Parameter(array(
180  'type' => $this->_fixType($parameter->getType()),
181  'name' => $parameter->getName(),
182  'optional' => $parameter->isOptional(),
183  ));
184  if ($parameter->isDefaultValueAvailable()) {
185  $param->setDefaultValue($parameter->getDefaultValue());
186  }
187  $prototype->addParameter($param);
188  }
189  $definition->addPrototype($prototype);
190  }
191  if (is_object($class)) {
192  $definition->setObject($class);
193  }
194  $this->_table->addMethod($definition);
195  return $definition;
196  }
197 
205  protected function _dispatch(Zend_Server_Method_Definition $invocable, array $params)
206  {
207  $callback = $invocable->getCallback();
208  $type = $callback->getType();
209 
210  if ('function' == $type) {
211  $function = $callback->getFunction();
212  return call_user_func_array($function, $params);
213  }
214 
215  $class = $callback->getClass();
216  $method = $callback->getMethod();
217 
218  if ('static' == $type) {
219  return call_user_func_array(array($class, $method), $params);
220  }
221 
222  $object = $invocable->getObject();
223  if (!is_object($object)) {
224  $invokeArgs = $invocable->getInvokeArguments();
225  if (!empty($invokeArgs)) {
226  $reflection = new ReflectionClass($class);
227  $object = $reflection->newInstanceArgs($invokeArgs);
228  } else {
229  $object = new $class;
230  }
231  }
232  return call_user_func_array(array($object, $method), $params);
233  }
234 
241  abstract protected function _fixType($type);
242 }
_dispatch(Zend_Server_Method_Definition $invocable, array $params)
Definition: Abstract.php:205
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setClass($class, $namespace='', $argv=null)
_buildSignature(Zend_Server_Reflection_Function_Abstract $reflection, $class=null)
Definition: Abstract.php:158
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
_buildCallback(Zend_Server_Reflection_Function_Abstract $reflection)
Definition: Abstract.php:136
static lowerCase(&$value, &$key)
Definition: Abstract.php:124
if(!isset($_GET['name'])) $name
Definition: log.php:14