/** * @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; }