/framework/vendor/zend/Zend/Reflection/Class.php

http://zoop.googlecode.com/ · PHP · 247 lines · 131 code · 18 blank · 98 comment · 21 complexity · fed7b983cbc14beb0993547c3dd87f32 MD5 · raw file

  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_Reflection
  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. * @version $Id: Class.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /**
  22. * @see Zend_Reflection_Property
  23. */
  24. require_once 'Zend/Reflection/Property.php';
  25. /**
  26. * @see Zend_Reflection_Method
  27. */
  28. require_once 'Zend/Reflection/Method.php';
  29. /**
  30. * Zend_Reflection_Docblock
  31. */
  32. require_once 'Zend/Reflection/Docblock.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Reflection
  36. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Reflection_Class extends ReflectionClass
  40. {
  41. /**
  42. * Return the reflection file of the declaring file.
  43. *
  44. * @return Zend_Reflection_File
  45. */
  46. public function getDeclaringFile($reflectionClass = 'Zend_Reflection_File')
  47. {
  48. $instance = new $reflectionClass($this->getFileName());
  49. if (!$instance instanceof Zend_Reflection_File) {
  50. require_once 'Zend/Reflection/Exception.php';
  51. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_File');
  52. }
  53. return $instance;
  54. }
  55. /**
  56. * Return the classes Docblock reflection object
  57. *
  58. * @param string $reflectionClass Name of reflection class to use
  59. * @return Zend_Reflection_Docblock
  60. * @throws Zend_Reflection_Exception for missing docblock or invalid reflection class
  61. */
  62. public function getDocblock($reflectionClass = 'Zend_Reflection_Docblock')
  63. {
  64. if ('' == $this->getDocComment()) {
  65. require_once 'Zend/Reflection/Exception.php';
  66. throw new Zend_Reflection_Exception($this->getName() . ' does not have a docblock');
  67. }
  68. $instance = new $reflectionClass($this);
  69. if (!$instance instanceof Zend_Reflection_Docblock) {
  70. require_once 'Zend/Reflection/Exception.php';
  71. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Docblock');
  72. }
  73. return $instance;
  74. }
  75. /**
  76. * Return the start line of the class
  77. *
  78. * @param bool $includeDocComment
  79. * @return int
  80. */
  81. public function getStartLine($includeDocComment = false)
  82. {
  83. if ($includeDocComment) {
  84. if ($this->getDocComment() != '') {
  85. return $this->getDocblock()->getStartLine();
  86. }
  87. }
  88. return parent::getStartLine();
  89. }
  90. /**
  91. * Return the contents of the class
  92. *
  93. * @param bool $includeDocblock
  94. * @return string
  95. */
  96. public function getContents($includeDocblock = true)
  97. {
  98. $filename = $this->getFileName();
  99. $filelines = file($filename);
  100. $startnum = $this->getStartLine($includeDocblock);
  101. $endnum = $this->getEndLine() - $this->getStartLine();
  102. return implode('', array_splice($filelines, $startnum, $endnum, true));
  103. }
  104. /**
  105. * Get all reflection objects of implemented interfaces
  106. *
  107. * @param string $reflectionClass Name of reflection class to use
  108. * @return array Array of Zend_Reflection_Class
  109. */
  110. public function getInterfaces($reflectionClass = 'Zend_Reflection_Class')
  111. {
  112. $phpReflections = parent::getInterfaces();
  113. $zendReflections = array();
  114. while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
  115. $instance = new $reflectionClass($phpReflection->getName());
  116. if (!$instance instanceof Zend_Reflection_Class) {
  117. require_once 'Zend/Reflection/Exception.php';
  118. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
  119. }
  120. $zendReflections[] = $instance;
  121. unset($phpReflection);
  122. }
  123. unset($phpReflections);
  124. return $zendReflections;
  125. }
  126. /**
  127. * Return method reflection by name
  128. *
  129. * @param string $name
  130. * @param string $reflectionClass Reflection class to utilize
  131. * @return Zend_Reflection_Method
  132. */
  133. public function getMethod($name, $reflectionClass = 'Zend_Reflection_Method')
  134. {
  135. $phpReflection = parent::getMethod($name);
  136. $zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
  137. if (!$zendReflection instanceof Zend_Reflection_Method) {
  138. require_once 'Zend/Reflection/Exception.php';
  139. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
  140. }
  141. unset($phpReflection);
  142. return $zendReflection;
  143. }
  144. /**
  145. * Get reflection objects of all methods
  146. *
  147. * @param string $filter
  148. * @param string $reflectionClass Reflection class to use for methods
  149. * @return array Array of Zend_Reflection_Method objects
  150. */
  151. public function getMethods($filter = -1, $reflectionClass = 'Zend_Reflection_Method')
  152. {
  153. $phpReflections = parent::getMethods($filter);
  154. $zendReflections = array();
  155. while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
  156. $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
  157. if (!$instance instanceof Zend_Reflection_Method) {
  158. require_once 'Zend/Reflection/Exception.php';
  159. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
  160. }
  161. $zendReflections[] = $instance;
  162. unset($phpReflection);
  163. }
  164. unset($phpReflections);
  165. return $zendReflections;
  166. }
  167. /**
  168. * Get parent reflection class of reflected class
  169. *
  170. * @param string $reflectionClass Name of Reflection class to use
  171. * @return Zend_Reflection_Class
  172. */
  173. public function getParentClass($reflectionClass = 'Zend_Reflection_Class')
  174. {
  175. $phpReflection = parent::getParentClass();
  176. if ($phpReflection) {
  177. $zendReflection = new $reflectionClass($phpReflection->getName());
  178. if (!$zendReflection instanceof Zend_Reflection_Class) {
  179. require_once 'Zend/Reflection/Exception.php';
  180. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
  181. }
  182. unset($phpReflection);
  183. return $zendReflection;
  184. } else {
  185. return false;
  186. }
  187. }
  188. /**
  189. * Return reflection property of this class by name
  190. *
  191. * @param string $name
  192. * @param string $reflectionClass Name of reflection class to use
  193. * @return Zend_Reflection_Property
  194. */
  195. public function getProperty($name, $reflectionClass = 'Zend_Reflection_Property')
  196. {
  197. $phpReflection = parent::getProperty($name);
  198. $zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
  199. if (!$zendReflection instanceof Zend_Reflection_Property) {
  200. require_once 'Zend/Reflection/Exception.php';
  201. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
  202. }
  203. unset($phpReflection);
  204. return $zendReflection;
  205. }
  206. /**
  207. * Return reflection properties of this class
  208. *
  209. * @param int $filter
  210. * @param string $reflectionClass Name of reflection class to use
  211. * @return array Array of Zend_Reflection_Property
  212. */
  213. public function getProperties($filter = -1, $reflectionClass = 'Zend_Reflection_Property')
  214. {
  215. $phpReflections = parent::getProperties($filter);
  216. $zendReflections = array();
  217. while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
  218. $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
  219. if (!$instance instanceof Zend_Reflection_Property) {
  220. require_once 'Zend/Reflection/Exception.php';
  221. throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
  222. }
  223. $zendReflections[] = $instance;
  224. unset($phpReflection);
  225. }
  226. unset($phpReflections);
  227. return $zendReflections;
  228. }
  229. }