| 1 | <?php |
||
| 20 | class MethodAnnotationReader { |
||
| 21 | |||
| 22 | private $annotations; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param object $object an object or classname |
||
| 26 | * @param string $method the method which we want to inspect for annotations |
||
| 27 | */ |
||
| 28 | public function __construct($object, $method){ |
||
| 29 | $this->annotations = array(); |
||
| 30 | |||
| 31 | $reflection = new \ReflectionMethod($object, $method); |
||
| 32 | $docs = $reflection->getDocComment(); |
||
| 33 | |||
| 34 | // extract everythin prefixed by @ and first letter uppercase |
||
| 35 | preg_match_all('/@([A-Z]\w+)/', $docs, $matches); |
||
| 36 | $this->annotations = $matches[1]; |
||
| 37 | } |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * Check if a method contains an annotation |
||
| 42 | * @param string $name the name of the annotation |
||
| 43 | * @return bool true if the annotation is found |
||
| 44 | */ |
||
| 45 | public function hasAnnotation($name){ |
||
| 48 | |||
| 49 | |||
| 50 | } |