Mpociot\Documentarian\Documentarian::create PHP Method

create() public method

Create a new API documentation folder and copy all needed files/stubs
public create ( $folder )
$folder
    public function create($folder)
    {
        $folder = $folder . '/source';
        if (!is_dir($folder)) {
            mkdir($folder, 0777, true);
            mkdir($folder . '/../css');
            mkdir($folder . '/../js');
            mkdir($folder . '/includes');
            mkdir($folder . '/assets');
        }
        // copy stub files
        copy(__DIR__ . '/../resources/stubs/index.md', $folder . '/index.md');
        copy(__DIR__ . '/../resources/stubs/gitignore.stub', $folder . '/.gitignore');
        copy(__DIR__ . '/../resources/stubs/includes/_errors.md', $folder . '/includes/_errors.md');
        copy(__DIR__ . '/../resources/stubs/package.json', $folder . '/package.json');
        copy(__DIR__ . '/../resources/stubs/gulpfile.js', $folder . '/gulpfile.js');
        copy(__DIR__ . '/../resources/stubs/config.php', $folder . '/config.php');
        copy(__DIR__ . '/../resources/stubs/js/all.js', $folder . '/../js/all.js');
        copy(__DIR__ . '/../resources/stubs/css/style.css', $folder . '/../css/style.css');
        // copy resources
        rcopy(__DIR__ . '/../resources/images/', $folder . '/assets/images');
        rcopy(__DIR__ . '/../resources/js/', $folder . '/assets/js');
        rcopy(__DIR__ . '/../resources/stylus/', $folder . '/assets/stylus');
    }

Usage Example

コード例 #1
0
 /**
  * @param  Collection $parsedRoutes
  *
  * @return void
  */
 private function writeMarkdown($parsedRoutes)
 {
     $outputPath = $this->option('output');
     $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
     $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
     $infoText = view('apidoc::partials.info')->with('outputPath', ltrim($outputPath, 'public/'))->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'));
     $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
         return $routeGroup->map(function ($route) {
             $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route);
             return $route;
         });
     });
     $frontmatter = view('apidoc::partials.frontmatter');
     /*
      * In case the target file already exists, we should check if the documentation was modified
      * and skip the modified parts of the routes.
      */
     if (file_exists($targetFile) && file_exists($compareFile)) {
         $generatedDocumentation = file_get_contents($targetFile);
         $compareDocumentation = file_get_contents($compareFile);
         if (preg_match('/<!-- START_INFO -->(.*)<!-- END_INFO -->/is', $generatedDocumentation, $generatedInfoText)) {
             $infoText = trim($generatedInfoText[1], "\n");
         }
         if (preg_match('/---(.*)---\\s<!-- START_INFO -->/is', $generatedDocumentation, $generatedFrontmatter)) {
             $frontmatter = trim($generatedFrontmatter[1], "\n");
         }
         $parsedRouteOutput->transform(function ($routeGroup) use($generatedDocumentation, $compareDocumentation) {
             return $routeGroup->transform(function ($route) use($generatedDocumentation, $compareDocumentation) {
                 if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $routeMatch)) {
                     $routeDocumentationChanged = preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1];
                     if ($routeDocumentationChanged === false || $this->option('force')) {
                         if ($routeDocumentationChanged) {
                             $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
                         }
                     } else {
                         $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
                         $route['modified_output'] = $routeMatch[0];
                     }
                 }
                 return $route;
             });
         });
     }
     $documentarian = new Documentarian();
     $markdown = view('apidoc::documentarian')->with('writeCompareFile', false)->with('frontmatter', $frontmatter)->with('infoText', $infoText)->with('outputPath', $this->option('output'))->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))->with('parsedRoutes', $parsedRouteOutput);
     if (!is_dir($outputPath)) {
         $documentarian->create($outputPath);
     }
     // Write output file
     file_put_contents($targetFile, $markdown);
     // Write comparable markdown file
     $compareMarkdown = view('apidoc::documentarian')->with('writeCompareFile', true)->with('frontmatter', $frontmatter)->with('infoText', $infoText)->with('outputPath', $this->option('output'))->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))->with('parsedRoutes', $parsedRouteOutput);
     file_put_contents($compareFile, $compareMarkdown);
     $this->info('Wrote index.md to: ' . $outputPath);
     $this->info('Generating API HTML code');
     $documentarian->generate($outputPath);
     $this->info('Wrote HTML documentation to: ' . $outputPath . '/public/index.html');
     if ($this->option('noPostmanCollection') !== true) {
         $this->info('Generating Postman collection');
         file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
     }
 }
All Usage Examples Of Mpociot\Documentarian\Documentarian::create