PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/Zend/Server/Reflection/Class.php

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