IPReflectionMethod.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * An extended reflection/documentation class for class methods
  4. *
  5. * This class extends the reflectioMethod 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 reflectionMethod
  13. */
  14. class IPReflectionMethod extends reflectionMethod{
  15. /** @var string class name */
  16. public $classname;
  17. /** @var string The return type for this method */
  18. public $return = "";
  19. /** @var IPReflectionParameter[] Associative array with reflectionParameter objects */
  20. public $parameters = array();
  21. /** @var string */
  22. public $fullDescription = "";
  23. /** @var string */
  24. public $smallDescription = "";
  25. /** @var string */
  26. public $throws="";
  27. /**
  28. * Constructor which calls the parent constructor and makes sure the comment
  29. * of the method is parsed
  30. *
  31. * @param string The class name
  32. * @param string The method name
  33. */
  34. public function __construct($class,$method){
  35. $this->classname = $class;
  36. parent::__construct($class,$method);
  37. $this->parseComment();
  38. }
  39. /**
  40. * Returns the full function name, including arguments
  41. * @return string
  42. */
  43. public function getFullName(){
  44. $args = $this->getParameters();
  45. $argstr = "";
  46. foreach((array)$args as $arg){
  47. if($argstr!="")$argstr.=", ";
  48. $argstr.= $arg->type ." $".$arg->name;
  49. }
  50. return $this->return." ".$this->name."(".$argstr.")";
  51. }
  52. /**
  53. * Returns an array with parameter objects, containing type info etc.
  54. *
  55. * @return ReflectionParameter[] Associative array with parameter objects
  56. */
  57. public function getParameters(){
  58. $this->parameters = Array();
  59. $ar = parent::getParameters();
  60. $i = 0;
  61. foreach((array)$ar as $parameter){
  62. $parameter->type = $this->params[$i++]->type;
  63. $this->parameters[$parameter->name] = $parameter;
  64. }
  65. return $this->parameters;
  66. }
  67. /**
  68. *
  69. * @param $annotationName String the annotation name
  70. * @param $annotationClass String the annotation class
  71. * @return void
  72. */
  73. public function getAnnotation($annotationName, $annotationClass = null){
  74. return IPPhpDoc::getAnnotation($this->comment, $annotationName, $annotationClass);
  75. }
  76. /**
  77. * Parses the comment and adds found properties to this class
  78. * @return void
  79. */
  80. private function parseComment(){
  81. $this->comment = $this->getDocComment();
  82. new IPReflectionCommentParser($this->comment, $this);
  83. }
  84. }
  85. ?>