Dingo\Blueprint\Blueprint::generate PHP Method

generate() public method

Generate documentation with the name and version.
public generate ( Collection $controllers, string $name, string $version, string $includePath ) : boolean
$controllers Illuminate\Support\Collection
$name string
$version string
$includePath string
return boolean
    public function generate(Collection $controllers, $name, $version, $includePath)
    {
        $this->includePath = $includePath;
        $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);
        });
        $contents = $this->generateContentsFromResources($resources, $name);
        $this->includePath = null;
        return $contents;
    }

Usage Example

Example #1
0
File: Docs.php Project: dingo/api
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $contents = $this->blueprint->generate($this->getControllers(), $this->getDocName(), $this->getVersion(), $this->getIncludePath());
     if ($file = $this->option('output-file')) {
         $this->writer->write($contents, $file);
         return $this->info('Documentation was generated successfully.');
     }
     return $this->line($contents);
 }