composer package updates
[openemr.git] / vendor / zendframework / zend-server / src / Reflection.php
blob5737bdc9320fdbaf560b23e0a611ead8fd3e83f9
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-server for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-server/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Server;
10 use Zend\Server\Reflection\ReflectionClass;
11 use Zend\Server\Reflection\ReflectionFunction;
13 /**
14 * Reflection for determining method signatures to use with server classes
16 class Reflection
18 /**
19 * Perform class reflection to create dispatch signatures
21 * Creates a {@link \Zend\Server\Reflection\ClassReflection} object for the class or
22 * object provided.
24 * If extra arguments should be passed to dispatchable methods, these may
25 * be provided as an array to $argv.
27 * @param string|object $class Class name or object
28 * @param bool|array $argv Optional arguments to be used during the method call
29 * @param string $namespace Optional namespace with which to prefix the
30 * method name (used for the signature key). Primarily to avoid collisions,
31 * also for XmlRpc namespacing
32 * @return \Zend\Server\Reflection\ReflectionClass
33 * @throws \Zend\Server\Reflection\Exception\InvalidArgumentException
35 public static function reflectClass($class, $argv = false, $namespace = '')
37 if (is_object($class)) {
38 $reflection = new \ReflectionObject($class);
39 } elseif (is_string($class) && class_exists($class)) {
40 $reflection = new \ReflectionClass($class);
41 } else {
42 throw new Reflection\Exception\InvalidArgumentException('Invalid class or object passed to attachClass()');
45 if ($argv && ! is_array($argv)) {
46 throw new Reflection\Exception\InvalidArgumentException('Invalid argv argument passed to reflectClass');
49 return new ReflectionClass($reflection, $namespace, $argv);
52 /**
53 * Perform function reflection to create dispatch signatures
55 * Creates dispatch prototypes for a function. It returns a
56 * {@link Zend\Server\Reflection\FunctionReflection} object.
58 * If extra arguments should be passed to the dispatchable function, these
59 * may be provided as an array to $argv.
61 * @param string $function Function name
62 * @param bool|array $argv Optional arguments to be used during the method call
63 * @param string $namespace Optional namespace with which to prefix the
64 * function name (used for the signature key). Primarily to avoid
65 * collisions, also for XmlRpc namespacing
66 * @return \Zend\Server\Reflection\ReflectionFunction
67 * @throws \Zend\Server\Reflection\Exception\InvalidArgumentException
69 public static function reflectFunction($function, $argv = false, $namespace = '')
71 if (! is_string($function) || ! function_exists($function)) {
72 throw new Reflection\Exception\InvalidArgumentException(sprintf(
73 'Invalid function "%s" passed to reflectFunction',
74 $function
75 ));
78 if ($argv && ! is_array($argv)) {
79 throw new Reflection\Exception\InvalidArgumentException('Invalid argv argument passed to reflectFunction');
82 return new ReflectionFunction(new \ReflectionFunction($function), $namespace, $argv);