/** * Get the @template annotation value for a particular auto-route callable * * @param \DocBlock\Element\MethodElement $method * * @return string */ private function getTemplateAnnotation(MethodElement $method) { $templateAnnotation = $method->getAnnotation(self::TEMPLATE); if (empty($templateAnnotation) || count($templateAnnotation->values) < 1) { return null; } return $templateAnnotation->values[0]; }
/** * Constructor * * @param array $annotations * @param MethodElement $method */ public function __construct($annotations, MethodElement $method) { $this->_annotations = $annotations; $this->_reflectionMethod = $method->getReflectionObject(); $this->_method = $method; }
/** * Analyzes a class or instance for PHP DocBlock comments * * @param array|string|object $classes A single string containing the name of the class to reflect, * or an object or an array of these * * @throws Exception */ public function analyze($classes) { if (empty($classes)) { return; } if (!is_array($classes)) { $classes = array($classes); } foreach ($classes as $classItem) { if (!is_string($classItem) && !is_object($classItem)) { throw new Exception("Please pass a valid classname or instance to the Parser::analyze function"); } $reflector = new ReflectionClass($classItem); $class = new ClassElement(); $class->setReflectionObject($reflector); $class->setName($reflector->getName()); if (is_object($classItem)) { $class->setInstance($classItem); } $this->methods = array(); $this->annotations = array(); preg_match_all($this->allDocBlockLinesRegex, $class->getReflectionObject()->getDocComment(), $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { $this->currentElement =& $class; $this->parse($result[0][$i]); } // a bug in the ReflectionClass makes getMethods behave unexpectedly when passed a NULL $methods = !$this->methodFilter ? $reflector->getMethods() : $reflector->getMethods($this->methodFilter); foreach ($methods as $method) { $this->currentAnnotation = null; if (!$this->allowInherited && $method->class !== $class->getName()) { continue; } $m = new MethodElement($class); $m->setName($method->getName()); $m->setReflectionObject($method); preg_match_all($this->allDocBlockLinesRegex, $method->getDocComment(), $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { $this->currentElement =& $m; $this->parse($result[0][$i]); } $this->methods[] = $m; $class->addMethod($m); } $this->classes[] = $class; } }