/** * @param string[] $dirs * @param string $fileMatch * @param string|null $cacheDir * * @return array * @throws RuntimeException */ protected function parseFiles(array $dirs, $fileMatch, $cacheDir = null) { $files = $this->filesystem->getFilesOfDirs($dirs, $fileMatch); $results = []; $tmpFile = $cacheDir !== null ? $cacheDir . '/' . $this->getCacheFile() : null; $oldCache = []; if ($tmpFile !== null && file_exists($tmpFile)) { $oldCache = unserialize(file_get_contents($tmpFile)); } foreach ($files as $file) { $realPath = $file->getRealPath(); if (!$realPath) { return []; } $hash = $this->filesystem->getFileHash($realPath); if (isset($oldCache[$hash])) { $fileResult = $this->fromCache($oldCache[$hash], $file); unset($oldCache[$hash]); } else { $fileResult = $this->parseFile($realPath); } $results[$hash] = $fileResult; } if ($tmpFile !== null) { $this->filesystem->writeFile($tmpFile, serialize($results)); } return $results; }
/** * @param State $state * @param Logger $logger * * @throws \RuntimeException */ public function run(State $state, Logger $logger) { $filesystem = new Filesystem(); $exportPath = $state->config->getExportDir() . '/'; foreach ($state->annotations as $annotation) { if ($annotation instanceof Topic) { if (!$annotation->file) { continue; } $file = $exportPath . $annotation->file; $filesystem->writeFile($file, $annotation->content); } } }
/** * @param State $state * @param Logger $logger * * @throws \RuntimeException */ public function run(State $state, Logger $logger) { $filesystem = new Filesystem(); $exportPath = $state->config->getExportDir() . '/'; foreach ($state->classes as $class) { if ($class->extends !== MarkupFunction::class) { continue; } if (!isset($class->constants['FUNC_NAME'])) { continue; } $funcName = $class->constants['FUNC_NAME']->value; $doc = $this->createFunctionDoc($class, $funcName, $state); $file = $exportPath . sprintf($this->path, $funcName); $filesystem->writeFile($file, $doc); } }