'application/Espo/{category}', 'modulePath' => 'application/Espo/Modules/{*}/{category}', 'customPath' => 'custom/Espo/Custom/{category}', ]; protected $dataHash = []; public function __construct(File\ClassParser $classParser) { $this->classParser = $classParser; } /** * Find class name by a category and name. */ public function find(string $category, string $name, bool $subDirs = false) : ?string { $map = $this->getMap($category, $subDirs); $className = $map[$name] ?? null; return $className; } /** * Get [name => class-name] map. */ public function getMap(string $category, bool $subDirs = false) : array { if (!array_key_exists($category, $this->dataHash)) { $this->load($category, $subDirs); } return $this->dataHash[$category] ?? []; } protected function load(string $category, bool $subDirs = false) { $path = $this->buildPaths($category); $cacheFile = $this->buildCacheFilePath($category); $this->dataHash[$category] = $this->classParser->getData($path, $cacheFile, null, $subDirs); } protected function buildPaths(string $category) : array { $paths = []; foreach ($this->pathsTemplate as $key => $value) { $path[$key] = str_replace('{category}', $category, $value); } return $path; } protected function buildCacheFilePath(string $category) : string { $path = 'data/cache/application/classmap_' . str_replace('/', '_', strtolower($category)) . '.php'; return $path; } }