IPReflectionClass.class.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * An extended reflection/documentation class for classes
  4. *
  5. * This class extends the reflectionClass class by also parsing the
  6. * comment for javadoc compatible @tags and by providing help
  7. * functions to generate a WSDL file. THe class might also
  8. * be used to generate a phpdoc on the fly
  9. *
  10. * @version 0.1
  11. * @author David Kingma
  12. * @extends reflectionClass
  13. */
  14. class IPReflectionClass extends reflectionClass {
  15. /** @var string class name */
  16. public $classname = null;
  17. /** @var string */
  18. public $fullDescription = "";
  19. /** @var string */
  20. public $smallDescription = "";
  21. /** @var IPReflectionMethod[] */
  22. public $methods = Array();
  23. /** @var IPReflectionProperty[] */
  24. public $properties = Array();
  25. /** @var string */
  26. public $extends;
  27. /** @var string */
  28. private $comment = null;
  29. /**
  30. * Constructor
  31. *
  32. * sets the class name and calls the constructor of the reflectionClass
  33. *
  34. * @param string The class name
  35. * @return void
  36. */
  37. public function __construct($classname){
  38. $this->classname = $classname;
  39. parent::__construct($classname);
  40. $this->parseComment();
  41. }
  42. /**
  43. *Levert een array met alle methoden van deze class op
  44. *
  45. * @param boolean If the method should also return protected functions
  46. * @param boolean If the method should also return private functions
  47. * @return IPReflectionMethod[]
  48. */
  49. public function getMethods($alsoProtected = true, $alsoPrivate = true){
  50. $ar = parent::getMethods();
  51. foreach($ar as $method){
  52. $m = new IPReflectionMethod($this->classname, $method->name);
  53. if((!$m->isPrivate() || $alsoPrivate) && (!$m->isProtected() || $alsoProtected) && ($m->getDeclaringClass()->name == $this->classname))
  54. $this->methods[$method->name] = $m;
  55. }
  56. ksort($this->methods);
  57. return $this->methods;
  58. }
  59. /**
  60. * Levert een array met variabelen van deze class op
  61. *
  62. * @param boolean If the method should also return protected properties
  63. * @param boolean If the method should also return private properties
  64. * @return IPReflectionProperty[]
  65. */
  66. public function getProperties($alsoProtected=true,$alsoPrivate=true) {
  67. $ar = parent::getProperties();
  68. $this->properties = Array();
  69. foreach($ar as $property){
  70. if((!$property->isPrivate() || $alsoPrivate) && (!$property->isProtected() || $alsoProtected)){
  71. try{
  72. $p = new IPReflectionProperty($this->classname, $property->getName());
  73. $this->properties[$property->name]=$p;
  74. }catch(ReflectionException $exception){
  75. echo "Fout bij property: ".$property->name."<br>\n";
  76. }
  77. }
  78. }
  79. ksort($this->properties);
  80. return $this->properties;
  81. }
  82. /**
  83. *
  84. * @param $annotationName String the annotation name
  85. * @param $annotationClass String the annotation class
  86. * @return void
  87. */
  88. public function getAnnotation($annotationName, $annotationClass = null){
  89. return IPPhpDoc::getAnnotation($this->comment, $annotationName, $annotationClass);
  90. }
  91. /**
  92. * Gets all the usefull information from the comments
  93. * @return void
  94. */
  95. private function parseComment() {
  96. $this->comment = $this->getDocComment();
  97. new IPReflectionCommentParser($this->comment, $this);
  98. }
  99. }
  100. ?>