/** * @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 * @throws MarkupException */ public function run(State $state, Logger $logger) { $filesystem = new Filesystem(); $from = realpath($state->config->getExportDir()); if (!$from) { throw new MarkupException('export dir does not exist'); } if (!$this->destination) { throw new MarkupException('destination no set'); } $to = $state->config->getBaseDir() . '/' . $this->destination; if ($this->purge) { $filesystem->purge($to); } $logger->log(0, sprintf('mirror export dir (%s -> %s)', $from, $to)); $filesystem->copy($from, $to); }
/** * @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); } }
/** * @param State $state * @param Logger $logger * * @throws \RuntimeException */ public function run(State $state, Logger $logger) { $filesystem = new Filesystem(); $docsDir = $state->config->getDocsDir(); $exportDir = $state->config->getExportDir(); $filesystem->ensureDir($exportDir); if ($docsDir === null) { $logger->log(0, 'skip copying docs to export dir (no docs dir configured)'); return; } $docsDir = realpath($docsDir); if ($docsDir === false) { $logger->log(0, 'skip copying docs to export dir (docs dir docs dir does not exist)'); return; } $logger->log(0, sprintf('copy docs to export dir (%s -> %s)', $docsDir, $exportDir)); $filesystem->mirror($docsDir, $exportDir); }
/** * @param string $content * @param FileContext $expected * * @return FileContext[] */ private function assertParsed($content, FileContext $expected) { $file = $this->createMock(\SplFileInfo::class); $file->expects(self::any())->method('getRealPath')->willReturn($this->fakeFileName); $this->filesystem->expects(self::any())->method('getFilesOfDirs')->willReturn([$file]); $this->filesystem->expects(self::any())->method('readFile')->willReturn($content); $this->filesystem->expects(self::any())->method('getFileHash')->willReturn($this->fakeFileHash); $parsed = $this->parser->parse('dir'); self::assertEquals([$this->fakeFileHash => $expected], $parsed); }