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

Public Member Functions

 __construct (Reflector $r, $namespace=null, $argv=array())
 
 __call ($method, $args)
 
 __get ($key)
 
 __set ($key, $value)
 
 setNamespace ($namespace)
 
 getNamespace ()
 
 setDescription ($string)
 
 getDescription ()
 
 getPrototypes ()
 
 getInvokeArguments ()
 
 __wakeup ()
 

Protected Member Functions

 _addTree (Zend_Server_Reflection_Node $parent, $level=0)
 
 _buildTree ()
 
 _buildSignatures ($return, $returnDesc, $paramTypes, $paramDesc)
 
 _reflect ()
 

Protected Attributes

 $_reflection
 
 $_argv = array()
 
 $_config = array()
 
 $_class
 
 $_description = ''
 
 $_namespace
 
 $_prototypes = array()
 

Detailed Description

Definition at line 53 of file Abstract.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Reflector  $r,
  $namespace = null,
  $argv = array() 
)

Constructor

Parameters
ReflectionFunction$r

Definition at line 110 of file Abstract.php.

111  {
112  // In PHP 5.1.x, ReflectionMethod extends ReflectionFunction. In 5.2.x,
113  // both extend ReflectionFunctionAbstract. So, we can't do normal type
114  // hinting in the prototype, but instead need to do some explicit
115  // testing here.
116  if ((!$r instanceof ReflectionFunction)
117  && (!$r instanceof ReflectionMethod)) {
118  #require_once 'Zend/Server/Reflection/Exception.php';
119  throw new Zend_Server_Reflection_Exception('Invalid reflection class');
120  }
121  $this->_reflection = $r;
122 
123  // Determine namespace
124  if (null !== $namespace){
125  $this->setNamespace($namespace);
126  }
127 
128  // Determine arguments
129  if (is_array($argv)) {
130  $this->_argv = $argv;
131  }
132 
133  // If method call, need to store some info on the class
134  if ($r instanceof ReflectionMethod) {
135  $this->_class = $r->getDeclaringClass()->getName();
136  }
137 
138  // Perform some introspection
139  $this->_reflect();
140  }

Member Function Documentation

◆ __call()

__call (   $method,
  $args 
)

Proxy reflection calls

Parameters
string$method
array$args
Returns
mixed

Definition at line 377 of file Abstract.php.

378  {
379  if (method_exists($this->_reflection, $method)) {
380  return call_user_func_array(array($this->_reflection, $method), $args);
381  }
382 
383  #require_once 'Zend/Server/Reflection/Exception.php';
384  throw new Zend_Server_Reflection_Exception('Invalid reflection method ("' .$method. '")');
385  }
$method
Definition: info.phtml:13

◆ __get()

__get (   $key)

Retrieve configuration parameters

Values are retrieved by key from $_config. Returns null if no value found.

Parameters
string$key
Returns
mixed

Definition at line 396 of file Abstract.php.

397  {
398  if (isset($this->_config[$key])) {
399  return $this->_config[$key];
400  }
401 
402  return null;
403  }

◆ __set()

__set (   $key,
  $value 
)

Set configuration parameters

Values are stored by $key in $_config.

Parameters
string$key
mixed$value
Returns
void

Definition at line 414 of file Abstract.php.

415  {
416  $this->_config[$key] = $value;
417  }
$value
Definition: gender.phtml:16

◆ __wakeup()

__wakeup ( )

Wakeup from serialization

Reflection needs explicit instantiation to work correctly. Re-instantiate reflection object on wakeup.

Returns
void

Definition at line 505 of file Abstract.php.

506  {
507  if ($this->_reflection instanceof ReflectionMethod) {
508  $class = new ReflectionClass($this->_class);
509  $this->_reflection = new ReflectionMethod($class->newInstance(), $this->getName());
510  } else {
511  $this->_reflection = new ReflectionFunction($this->getName());
512  }
513  }
$_option $_optionId $class
Definition: date.phtml:13

◆ _addTree()

_addTree ( Zend_Server_Reflection_Node  $parent,
  $level = 0 
)
protected

Create signature node tree

Recursive method to build the signature node tree. Increments through each array in $_sigParams, adding every value of the next level to the current value (unless the current value is null).

Parameters
Zend_Server_Reflection_Node$parent
int$level
Returns
void

Definition at line 153 of file Abstract.php.

154  {
155  if ($level >= $this->_sigParamsDepth) {
156  return;
157  }
158 
159  foreach ($this->_sigParams[$level] as $value) {
160  $node = new Zend_Server_Reflection_Node($value, $parent);
161  if ((null !== $value) && ($this->_sigParamsDepth > $level + 1)) {
162  $this->_addTree($node, $level + 1);
163  }
164  }
165  }
_addTree(Zend_Server_Reflection_Node $parent, $level=0)
Definition: Abstract.php:153
$value
Definition: gender.phtml:16

◆ _buildSignatures()

_buildSignatures (   $return,
  $returnDesc,
  $paramTypes,
  $paramDesc 
)
protected

Build method signatures

Builds method signatures using the array of return types and the array of parameters types

Parameters
array$returnArray of return types
string$returnDescReturn value description
array$paramsArray of arguments (each an array of types)
array$paramDescArray of parameter descriptions
Returns
array

Definition at line 200 of file Abstract.php.

201  {
202  $this->_return = $return;
203  $this->_returnDesc = $returnDesc;
204  $this->_paramDesc = $paramDesc;
205  $this->_sigParams = $paramTypes;
206  $this->_sigParamsDepth = count($paramTypes);
207  $signatureTrees = $this->_buildTree();
208  $signatures = array();
209 
210  $endPoints = array();
211  foreach ($signatureTrees as $root) {
212  $tmp = $root->getEndPoints();
213  if (empty($tmp)) {
214  $endPoints = array_merge($endPoints, array($root));
215  } else {
216  $endPoints = array_merge($endPoints, $tmp);
217  }
218  }
219 
220  foreach ($endPoints as $node) {
221  if (!$node instanceof Zend_Server_Reflection_Node) {
222  continue;
223  }
224 
225  $signature = array();
226  do {
227  array_unshift($signature, $node->getValue());
228  $node = $node->getParent();
229  } while ($node instanceof Zend_Server_Reflection_Node);
230 
231  $signatures[] = $signature;
232  }
233 
234  // Build prototypes
235  $params = $this->_reflection->getParameters();
236  foreach ($signatures as $signature) {
237  $return = new Zend_Server_Reflection_ReturnValue(array_shift($signature), $this->_returnDesc);
238  $tmp = array();
239  foreach ($signature as $key => $type) {
240  $param = new Zend_Server_Reflection_Parameter($params[$key], $type, (isset($this->_paramDesc[$key]) ? $this->_paramDesc[$key] : null));
241  $param->setPosition($key);
242  $tmp[] = $param;
243  }
244 
245  $this->_prototypes[] = new Zend_Server_Reflection_Prototype($return, $tmp);
246  }
247  }
$type
Definition: item.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _buildTree()

_buildTree ( )
protected

Build the signature tree

Builds a signature tree starting at the return values and descending through each method argument. Returns an array of Zend_Server_Reflection_Nodes.

Returns
array

Definition at line 176 of file Abstract.php.

177  {
178  $returnTree = array();
179  foreach ((array) $this->_return as $value) {
180  $node = new Zend_Server_Reflection_Node($value);
181  $this->_addTree($node);
182  $returnTree[] = $node;
183  }
184 
185  return $returnTree;
186  }
_addTree(Zend_Server_Reflection_Node $parent, $level=0)
Definition: Abstract.php:153
$value
Definition: gender.phtml:16

◆ _reflect()

_reflect ( )
protected

Use code reflection to create method signatures

Determines the method help/description text from the function DocBlock comment. Determines method signatures using a combination of ReflectionFunction and parsing of DocBlock

Parameters
and
Returns
values.
Parameters
ReflectionFunction$function
Returns
array

Definition at line 259 of file Abstract.php.

260  {
261  $function = $this->_reflection;
262  $helpText = '';
263  $signatures = array();
264  $returnDesc = '';
265  $paramCount = $function->getNumberOfParameters();
266  $paramCountRequired = $function->getNumberOfRequiredParameters();
267  $parameters = $function->getParameters();
268  $docBlock = $function->getDocComment();
269 
270  if (!empty($docBlock)) {
271  // Get help text
272  if (preg_match(':/\*\*\s*\r?\n\s*\*\s(.*?)\r?\n\s*\*(\s@|/):s', $docBlock, $matches))
273  {
274  $helpText = $matches[1];
275  $helpText = preg_replace('/(^\s*\*\s)/m', '', $helpText);
276  $helpText = preg_replace('/\r?\n\s*\*\s*(\r?\n)*/s', "\n", $helpText);
277  $helpText = trim($helpText);
278  }
279 
280  // Get return type(s) and description
281  $return = 'void';
282  if (preg_match('/@return\s+(\S+)/', $docBlock, $matches)) {
283  $return = explode('|', $matches[1]);
284  if (preg_match('/@return\s+\S+\s+(.*?)(@|\*\/)/s', $docBlock, $matches))
285  {
286  $value = $matches[1];
287  $value = preg_replace('/\s?\*\s/m', '', $value);
288  $value = preg_replace('/\s{2,}/', ' ', $value);
289  $returnDesc = trim($value);
290  }
291  }
292 
293  // Get param types and description
294  if (preg_match_all('/@param\s+([^\s]+)/m', $docBlock, $matches)) {
295  $paramTypesTmp = $matches[1];
296  if (preg_match_all('/@param\s+\S+\s+(\$\S+)\s+(.*?)(?=@|\*\/)/s', $docBlock, $matches))
297  {
298  $paramDesc = $matches[2];
299  foreach ($paramDesc as $key => $value) {
300  $value = preg_replace('/\s?\*\s/m', '', $value);
301  $value = preg_replace('/\s{2,}/', ' ', $value);
302  $paramDesc[$key] = trim($value);
303  }
304  }
305  }
306  } else {
307  $helpText = $function->getName();
308  $return = 'void';
309 
310  // Try and auto-determine type, based on reflection
311  $paramTypesTmp = array();
312  foreach ($parameters as $i => $param) {
313  $paramType = 'mixed';
314  if ($param->isArray()) {
315  $paramType = 'array';
316  }
317  $paramTypesTmp[$i] = $paramType;
318  }
319  }
320 
321  // Set method description
322  $this->setDescription($helpText);
323 
324  // Get all param types as arrays
325  if (!isset($paramTypesTmp) && (0 < $paramCount)) {
326  $paramTypesTmp = array_fill(0, $paramCount, 'mixed');
327  } elseif (!isset($paramTypesTmp)) {
328  $paramTypesTmp = array();
329  } elseif (count($paramTypesTmp) < $paramCount) {
330  $start = $paramCount - count($paramTypesTmp);
331  for ($i = $start; $i < $paramCount; ++$i) {
332  $paramTypesTmp[$i] = 'mixed';
333  }
334  }
335 
336  // Get all param descriptions as arrays
337  if (!isset($paramDesc) && (0 < $paramCount)) {
338  $paramDesc = array_fill(0, $paramCount, '');
339  } elseif (!isset($paramDesc)) {
340  $paramDesc = array();
341  } elseif (count($paramDesc) < $paramCount) {
342  $start = $paramCount - count($paramDesc);
343  for ($i = $start; $i < $paramCount; ++$i) {
344  $paramDesc[$i] = '';
345  }
346  }
347 
348  if (count($paramTypesTmp) != $paramCount) {
349  #require_once 'Zend/Server/Reflection/Exception.php';
351  'Variable number of arguments is not supported for services (except optional parameters). '
352  . 'Number of function arguments in ' . $function->getDeclaringClass()->getName() . '::'
353  . $function->getName() . '() must correspond to actual number of arguments described in the '
354  . 'docblock.');
355  }
356 
357  $paramTypes = array();
358  foreach ($paramTypesTmp as $i => $param) {
359  $tmp = explode('|', $param);
360  if ($parameters[$i]->isOptional()) {
361  array_unshift($tmp, null);
362  }
363  $paramTypes[] = $tmp;
364  }
365 
366  $this->_buildSignatures($return, $returnDesc, $paramTypes, $paramDesc);
367  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$start
Definition: listing.phtml:18
$value
Definition: gender.phtml:16
_buildSignatures($return, $returnDesc, $paramTypes, $paramDesc)
Definition: Abstract.php:200
$i
Definition: gallery.phtml:31

◆ getDescription()

getDescription ( )

Retrieve the description

Returns
void

Definition at line 471 of file Abstract.php.

◆ getInvokeArguments()

getInvokeArguments ( )

Retrieve additional invocation arguments

Returns
array

Definition at line 492 of file Abstract.php.

493  {
494  return $this->_argv;
495  }

◆ getNamespace()

getNamespace ( )

Return method's namespace

Returns
string

Definition at line 445 of file Abstract.php.

◆ getPrototypes()

getPrototypes ( )

Retrieve all prototypes as array of Zend_Server_Reflection_Prototypes

Returns
array

Definition at line 482 of file Abstract.php.

◆ setDescription()

setDescription (   $string)

Set the description

Parameters
string$string
Returns
void

Definition at line 456 of file Abstract.php.

457  {
458  if (!is_string($string)) {
459  #require_once 'Zend/Server/Reflection/Exception.php';
460  throw new Zend_Server_Reflection_Exception('Invalid description');
461  }
462 
463  $this->_description = $string;
464  }

◆ setNamespace()

setNamespace (   $namespace)

Set method's namespace

Parameters
string$namespace
Returns
void

Definition at line 425 of file Abstract.php.

426  {
427  if (empty($namespace)) {
428  $this->_namespace = '';
429  return;
430  }
431 
432  if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) {
433  #require_once 'Zend/Server/Reflection/Exception.php';
434  throw new Zend_Server_Reflection_Exception('Invalid namespace');
435  }
436 
437  $this->_namespace = $namespace;
438  }

Field Documentation

◆ $_argv

$_argv = array()
protected

Definition at line 64 of file Abstract.php.

◆ $_class

$_class
protected

Definition at line 79 of file Abstract.php.

◆ $_config

$_config = array()
protected

Definition at line 73 of file Abstract.php.

◆ $_description

$_description = ''
protected

Definition at line 85 of file Abstract.php.

◆ $_namespace

$_namespace
protected

Definition at line 91 of file Abstract.php.

◆ $_prototypes

$_prototypes = array()
protected

Definition at line 97 of file Abstract.php.

◆ $_reflection

$_reflection
protected

Definition at line 58 of file Abstract.php.


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