3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Server\Reflection
;
12 use ReflectionClass
as PhpReflectionClass
;
15 * Class/Object reflection
17 * Proxies calls to a ReflectionClass object, and decorates getMethods() by
18 * creating its own list of {@link Zend\Server\Reflection\ReflectionMethod}s.
23 * Optional configuration parameters; accessible via {@link __get} and
27 protected $config = array();
30 * Array of {@link \Zend\Server\Reflection\Method}s
33 protected $methods = array();
39 protected $namespace = null;
42 * ReflectionClass object
43 * @var PhpReflectionClass
45 protected $reflection;
50 * Create array of dispatchable methods, each a
51 * {@link Zend\Server\Reflection\ReflectionMethod}. Sets reflection object property.
53 * @param PhpReflectionClass $reflection
54 * @param string $namespace
57 public function __construct(PhpReflectionClass
$reflection, $namespace = null, $argv = false)
59 $this->reflection
= $reflection;
60 $this->setNamespace($namespace);
62 foreach ($reflection->getMethods() as $method) {
63 // Don't aggregate magic methods
64 if ('__' == substr($method->getName(), 0, 2)) {
68 if ($method->isPublic()) {
69 // Get signatures and description
70 $this->methods
[] = new ReflectionMethod($this, $method, $this->getNamespace(), $argv);
76 * Proxy reflection calls
78 * @param string $method
80 * @throws Exception\BadMethodCallException
83 public function __call($method, $args)
85 if (method_exists($this->reflection
, $method)) {
86 return call_user_func_array(array($this->reflection
, $method), $args);
89 throw new Exception\
BadMethodCallException('Invalid reflection method');
93 * Retrieve configuration parameters
95 * Values are retrieved by key from {@link $config}. Returns null if no
101 public function __get($key)
103 if (isset($this->config
[$key])) {
104 return $this->config
[$key];
111 * Set configuration parameters
113 * Values are stored by $key in {@link $config}.
116 * @param mixed $value
119 public function __set($key, $value)
121 $this->config
[$key] = $value;
125 * Return array of dispatchable {@link \Zend\Server\Reflection\ReflectionMethod}s.
130 public function getMethods()
132 return $this->methods
;
136 * Get namespace for this class
140 public function getNamespace()
142 return $this->namespace;
146 * Set namespace for this class
148 * @param string $namespace
149 * @throws Exception\InvalidArgumentException
152 public function setNamespace($namespace)
154 if (empty($namespace)) {
155 $this->namespace = '';
159 if (!is_string($namespace) ||
!preg_match('/[a-z0-9_\.]+/i', $namespace)) {
160 throw new Exception\
InvalidArgumentException('Invalid namespace');
163 $this->namespace = $namespace;
167 * Wakeup from serialization
169 * Reflection needs explicit instantiation to work correctly. Re-instantiate
170 * reflection object on wakeup.
174 public function __wakeup()
176 $this->reflection
= new PhpReflectionClass($this->getName());