addFile() public méthode

Adds file to context
public addFile ( string $fileName )
$fileName string
 protected function populateElasticsearch1x($source, $target)
 {
     // search for files to process
     if (($files = $this->searchFiles($source)) === false) {
         return false;
     }
     // load context from cache
     $context = $this->loadContext($target);
     $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();
             if (($files = $this->searchFiles($source)) === false) {
                 return false;
             }
             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) {
         if (file_exists("{$target}/api/" . basename($file, '.php') . '.html')) {
             $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, $target);
     $this->updateContext($context);
     $types = array_merge($context->classes, $context->interfaces, $context->traits);
     try {
         Console::startProgress(0, $count = count($types), 'populating elasticsearch index...', false);
         $version = $this->version;
         // first delete all records for this version
         SearchApiType::setMappings();
         SearchApiPrimitive::setMappings();
         //        ApiPrimitive::deleteAllForVersion($version);
         //        SearchApiType::deleteAllForVersion($version);
         sleep(1);
         $i = 0;
         foreach ($types as $type) {
             SearchApiType::createRecord($type, $version);
             Console::updateProgress(++$i, $count);
         }
         Console::endProgress(true, true);
         $this->stdout("done.\n", Console::FG_GREEN);
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             $this->stdout("!!! FAILED !!! Search will not be available.\n", Console::FG_RED, Console::BOLD);
             $this->stdout((string) $e . "\n\n");
         } else {
             throw $e;
         }
     }
     $this->writeJsonFiles1x($target, $types);
     return true;
 }
Exemple #2
0
 /**
  * Renders API documentation files
  * @param array $sourceDirs
  * @param string $targetDir
  * @return int
  */
 public function actionIndex(array $sourceDirs, $targetDir)
 {
     $renderer = $this->findRenderer($this->template);
     $targetDir = $this->normalizeTargetDir($targetDir);
     if ($targetDir === false || $renderer === false) {
         return 1;
     }
     $renderer->apiUrl = './';
     $renderer->guidePrefix = $this->guidePrefix;
     if ($this->pageTitle !== null) {
         $renderer->pageTitle = $this->pageTitle;
     }
     // setup reference to guide
     if ($this->guide !== null) {
         $renderer->guideUrl = $guideUrl = $this->guide;
     } else {
         $guideUrl = './';
         $renderer->guideUrl = $targetDir;
         if (file_exists($renderer->generateGuideUrl('README.md'))) {
             $renderer->guideUrl = $guideUrl;
         } else {
             $renderer->guideUrl = null;
         }
     }
     // search for files to process
     if (($files = $this->searchFiles($sourceDirs)) === false) {
         return 1;
     }
     // 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();
             if (($files = $this->searchFiles($sourceDirs)) === false) {
                 return 1;
             }
             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);
     }
 }