PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/zend/Zend/Server/Reflection/Class.php

http://github.com/moodle/moodle
PHP | 198 lines | 65 code | 19 blank | 114 comment | 8 complexity | 9c5f13418bb8e4c1048f68997c08adb9 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Server
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * Zend_Server_Reflection_Method
  22. */
  23. require_once 'Zend/Server/Reflection/Method.php';
  24. /**
  25. * Class/Object reflection
  26. *
  27. * Proxies calls to a ReflectionClass object, and decorates getMethods() by
  28. * creating its own list of {@link Zend_Server_Reflection_Method}s.
  29. *
  30. * @category Zend
  31. * @package Zend_Server
  32. * @subpackage Reflection
  33. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @version $Id$
  36. */
  37. class Zend_Server_Reflection_Class
  38. {
  39. /**
  40. * Optional configuration parameters; accessible via {@link __get} and
  41. * {@link __set()}
  42. * @var array
  43. */
  44. protected $_config = array();
  45. /**
  46. * Array of {@link Zend_Server_Reflection_Method}s
  47. * @var array
  48. */
  49. protected $_methods = array();
  50. /**
  51. * Namespace
  52. * @var string
  53. */
  54. protected $_namespace = null;
  55. /**
  56. * ReflectionClass object
  57. * @var ReflectionClass
  58. */
  59. protected $_reflection;
  60. /**
  61. * Constructor
  62. *
  63. * Create array of dispatchable methods, each a
  64. * {@link Zend_Server_Reflection_Method}. Sets reflection object property.
  65. *
  66. * @param ReflectionClass $reflection
  67. * @param string $namespace
  68. * @param mixed $argv
  69. * @return void
  70. */
  71. public function __construct(ReflectionClass $reflection, $namespace = null, $argv = false)
  72. {
  73. $this->_reflection = $reflection;
  74. $this->setNamespace($namespace);
  75. foreach ($reflection->getMethods() as $method) {
  76. // Don't aggregate magic methods
  77. if ('__' == substr($method->getName(), 0, 2)) {
  78. continue;
  79. }
  80. if ($method->isPublic()) {
  81. // Get signatures and description
  82. $this->_methods[] = new Zend_Server_Reflection_Method($this, $method, $this->getNamespace(), $argv);
  83. }
  84. }
  85. }
  86. /**
  87. * Proxy reflection calls
  88. *
  89. * @param string $method
  90. * @param array $args
  91. * @return mixed
  92. */
  93. public function __call($method, $args)
  94. {
  95. if (method_exists($this->_reflection, $method)) {
  96. return call_user_func_array(array($this->_reflection, $method), $args);
  97. }
  98. require_once 'Zend/Server/Reflection/Exception.php';
  99. throw new Zend_Server_Reflection_Exception('Invalid reflection method');
  100. }
  101. /**
  102. * Retrieve configuration parameters
  103. *
  104. * Values are retrieved by key from {@link $_config}. Returns null if no
  105. * value found.
  106. *
  107. * @param string $key
  108. * @return mixed
  109. */
  110. public function __get($key)
  111. {
  112. if (isset($this->_config[$key])) {
  113. return $this->_config[$key];
  114. }
  115. return null;
  116. }
  117. /**
  118. * Set configuration parameters
  119. *
  120. * Values are stored by $key in {@link $_config}.
  121. *
  122. * @param string $key
  123. * @param mixed $value
  124. * @return void
  125. */
  126. public function __set($key, $value)
  127. {
  128. $this->_config[$key] = $value;
  129. }
  130. /**
  131. * Return array of dispatchable {@link Zend_Server_Reflection_Method}s.
  132. *
  133. * @access public
  134. * @return array
  135. */
  136. public function getMethods()
  137. {
  138. return $this->_methods;
  139. }
  140. /**
  141. * Get namespace for this class
  142. *
  143. * @return string
  144. */
  145. public function getNamespace()
  146. {
  147. return $this->_namespace;
  148. }
  149. /**
  150. * Set namespace for this class
  151. *
  152. * @param string $namespace
  153. * @return void
  154. */
  155. public function setNamespace($namespace)
  156. {
  157. if (empty($namespace)) {
  158. $this->_namespace = '';
  159. return;
  160. }
  161. if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) {
  162. require_once 'Zend/Server/Reflection/Exception.php';
  163. throw new Zend_Server_Reflection_Exception('Invalid namespace');
  164. }
  165. $this->_namespace = $namespace;
  166. }
  167. /**
  168. * Wakeup from serialization
  169. *
  170. * Reflection needs explicit instantiation to work correctly. Re-instantiate
  171. * reflection object on wakeup.
  172. *
  173. * @return void
  174. */
  175. public function __wakeup()
  176. {
  177. $this->_reflection = new ReflectionClass($this->getName());
  178. }
  179. }