示例#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);
 }
 /**
  * Gets an annotation.
  *
  * @param  mixed  $from
  * @param  string $name
  * @return Annotation
  */
 protected function getAnnotation($from, $name)
 {
     if (!$this->reader) {
         $this->reader = new SimpleAnnotationReader();
         $this->reader->addNamespace($this->namespace);
     }
     $name = "{$this->namespace}\\{$name}";
     if ($from instanceof \ReflectionClass) {
         $annotation = $this->reader->getClassAnnotation($from, $name);
     } elseif ($from instanceof \ReflectionMethod) {
         $annotation = $this->reader->getMethodAnnotation($from, $name);
     } elseif ($from instanceof \ReflectionProperty) {
         $annotation = $this->reader->getPropertyAnnotation($from, $name);
     }
     return $annotation;
 }