'application/Espo/{category}', 'modulePath' => 'application/Espo/Modules/{*}/{category}', 'customPath' => 'custom/Espo/Custom/{category}', ]; private $dataHashMap = []; public function __construct(ClassMap $classMap) { $this->classMap = $classMap; } /** * 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 a name => class name map. * * @return array */ public function getMap(string $category, bool $subDirs = false): array { if (!array_key_exists($category, $this->dataHashMap)) { $this->load($category, $subDirs); } return $this->dataHashMap[$category] ?? []; } private function load(string $category, bool $subDirs = false): void { $path = $this->buildPaths($category); $cacheFile = $this->buildCacheKey($category); $this->dataHashMap[$category] = $this->classMap->getData($path, $cacheFile, null, $subDirs); } private function buildPaths(string $category): array { $paths = []; foreach ($this->pathsTemplate as $key => $value) { $paths[$key] = str_replace('{category}', $category, $value); } return $paths; } private function buildCacheKey(string $category): string { return 'classmap' . str_replace('/', '', $category); } }