Google\Cloud\Dev\DocGenerator\DocGenerator::generate PHP Méthode

generate() public méthode

Generates JSON documentation from provided files.
public generate ( ) : void
Résultat void
    public function generate()
    {
        foreach ($this->files as $file) {
            $currentFile = substr(str_replace($this->executionPath, '', $file), 3);
            $isPhp = strrpos($file, '.php') == strlen($file) - strlen('.php');
            if ($isPhp) {
                $fileReflector = new FileReflector($file);
                $parser = new CodeParser($file, $currentFile, $fileReflector);
            } else {
                $content = file_get_contents($file);
                $parser = new MarkdownParser($currentFile, $content);
            }
            $document = $parser->parse();
            $writer = new Writer(json_encode($document), $this->outputPath);
            $writer->write(substr($currentFile, 4));
            $this->types->addType(['id' => $document['id'], 'title' => $document['title'], 'contents' => $document['id'] . '.json']);
        }
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $paths = ['source' => $input->getArgument('source') ? $this->cliBasePath . '/../' . $input->getArgument('source') : $this->cliBasePath . '/../' . self::DEFAULT_SOURCE_DIR, 'output' => $input->getArgument('output') ? $this->cliBasePath . '/../' . $input->getArgument('output') : $this->cliBasePath . '/../' . self::DEFAULT_OUTPUT_DIR];
     $types = new TypeGenerator($paths['output']);
     $sourceFiles = $this->getFilesList($paths['source']);
     $docs = new DocGenerator($types, $sourceFiles, $paths['output'], $this->cliBasePath);
     $docs->generate();
     $types->write();
 }