示例#1
0
 /**
  * Generate documentation with the name and version.
  *
  * @param string $name
  * @param string $version
  *
  * @return bool
  */
 public function generate(Collection $controllers, $name, $version)
 {
     $resources = $controllers->map(function ($controller) use($version) {
         $controller = $controller instanceof ReflectionClass ? $controller : new ReflectionClass($controller);
         $actions = new Collection();
         // Spin through all the methods on the controller and compare the version
         // annotation (if supplied) with the version given for the generation.
         // We'll also build up an array of actions on each resource.
         foreach ($controller->getMethods() as $method) {
             if ($versionAnnotation = $this->reader->getMethodAnnotation($method, Annotation\Versions::class)) {
                 if (!in_array($version, $versionAnnotation->value)) {
                     continue;
                 }
             }
             if ($annotations = $this->reader->getMethodAnnotations($method)) {
                 if (!$actions->contains($method)) {
                     $actions->push(new Action($method, new Collection($annotations)));
                 }
             }
         }
         $annotations = new Collection($this->reader->getClassAnnotations($controller));
         return new Resource($controller->getName(), $controller, $annotations, $actions);
     });
     return $this->generateContentsFromResources($resources, $name);
 }
 /**
  * @param type $class
  * @return \Nucleus\Annotation\IParsingResult
  */
 public function parse($className)
 {
     $reflectionClass = new \ReflectionClass($className);
     $result = new ParsingResult($reflectionClass->getName());
     $result->setClassAnnotations($this->reader->getClassAnnotations($reflectionClass));
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $result->setMethodAnnotations($reflectionMethod->getName(), $this->reader->getMethodAnnotations($reflectionMethod));
     }
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $result->setMethodAnnotations($reflectionMethod->getName(), $this->reader->getMethodAnnotations($reflectionMethod));
     }
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         $result->setPropertyAnnotations($reflectionProperty->getName(), $this->reader->getPropertyAnnotations($reflectionProperty));
     }
     $parentClass = $reflectionClass->getParentClass();
     if ($parentClass) {
         $parentResult = $this->parse($parentClass->getName());
         $result->mergeParentClass($parentResult);
     }
     $interfaceClasses = $reflectionClass->getInterfaces();
     foreach ($interfaceClasses as $interfaceClass) {
         /* @var $interfaceClass \ReflectionClass  */
         $interfaceResult = $this->parse($interfaceClass->getName());
         $result->mergeParentClass($interfaceResult);
     }
     return $result;
 }
 /**
  * Get the method annotations for a given class.
  *
  * @param  \ReflectionClass  $class
  * @param  \Doctrine\Common\Annotations\SimpleAnnotationReader  $reader
  * @return array
  */
 protected function getMethodAnnotations(ReflectionClass $class, SimpleAnnotationReader $reader)
 {
     $annotations = [];
     foreach ($class->getMethods() as $method) {
         $results = $reader->getMethodAnnotations($method);
         if (count($results) > 0) {
             $annotations[$method->name] = $results;
         }
     }
     return $annotations;
 }