findRenderer($this->template); $targetDir = $this->normalizeTargetDir($targetDir); if ($targetDir === false || $renderer === false) { return 1; } $renderer->apiUrl = './'; // setup reference to guide if ($this->guide !== null) { $guideUrl = $this->guide; $referenceFile = $guideUrl . '/' . BaseRenderer::GUIDE_PREFIX . 'references.txt'; } else { $guideUrl = './'; $referenceFile = $targetDir . '/' . BaseRenderer::GUIDE_PREFIX . 'references.txt'; } if (file_exists($referenceFile)) { $renderer->guideUrl = $guideUrl; $renderer->guideReferences = []; foreach(explode("\n", file_get_contents($referenceFile)) as $reference) { $renderer->guideReferences[BaseRenderer::GUIDE_PREFIX . $reference]['url'] = $renderer->generateGuideUrl($reference); } } // search for files to process $files = $this->searchFiles($sourceDirs); // load context from cache $context = $this->loadContext($targetDir); $this->stdout('Checking for updated files... '); foreach($context->files as $file => $sha) { if (!file_exists($file)) { $this->stdout('At least one file has been removed. Rebuilding the context...'); $context = new Context(); $files = $this->searchFiles($sourceDirs); break; } if (sha1_file($file) === $sha) { unset($files[$file]); } } $this->stdout('done.' . PHP_EOL, Console::FG_GREEN); // process files $fileCount = count($files); $this->stdout($fileCount . ' file' . ($fileCount == 1 ? '' : 's') . ' to update.' . PHP_EOL); Console::startProgress(0, $fileCount, 'Processing files... ', false); $done = 0; foreach($files as $file) { $context->addFile($file); Console::updateProgress(++$done, $fileCount); } Console::endProgress(true); $this->stdout('done.' . PHP_EOL, Console::FG_GREEN); // save processed data to cache $this->storeContext($context, $targetDir); $this->updateContext($context); // render models $renderer->controller = $this; $renderer->render($context, $targetDir); if (!empty($context->errors)) { ArrayHelper::multisort($context->errors, 'file'); file_put_contents($targetDir . '/errors.txt', print_r($context->errors, true)); $this->stdout(count($context->errors) . " errors have been logged to $targetDir/errors.txt\n", Console::FG_RED, Console::BOLD); } } protected function findFiles($path, $except = ['vendor/', 'tests/']) { $path = FileHelper::normalizePath($path); $options = [ 'filter' => function ($path) { if (is_file($path)) { $file = basename($path); if ($file[0] < 'A' || $file[0] > 'Z') { return false; } } return null; }, 'only' => ['*.php'], 'except' => $except, ]; return FileHelper::findFiles($path, $options); } /** * @return ApiRenderer */ protected function findRenderer($template) { $rendererClass = 'yii\\apidoc\\templates\\' . $template . '\\ApiRenderer'; if (!class_exists($rendererClass)) { $this->stderr('Renderer not found.' . PHP_EOL); return false; } return new $rendererClass(); } /** * @inheritdoc */ public function globalOptions() { return array_merge(parent::globalOptions(), ['template', 'guide']); } }