private function findRepositories($config) { $classes = []; if ($config['scanDirs']) { $robot = new RobotLoader(); $robot->setCacheStorage(new Nette\Caching\Storages\DevNullStorage()); $robot->addDirectory($config['scanDirs']); $robot->acceptFiles = '*.php'; $robot->rebuild(); $classes = array_keys($robot->getIndexedClasses()); } $repositories = []; foreach (array_unique($classes) as $class) { if (class_exists($class) && ($rc = new \ReflectionClass($class)) && $rc->isSubclassOf('Joseki\\LeanMapper\\Repository') && !$rc->isAbstract()) { $repositoryClass = $rc->getName(); $entityClass = Strings::endsWith($repositoryClass, 'Repository') ? substr($repositoryClass, 0, strlen($repositoryClass) - 10) : $repositoryClass; $table = Utils::camelToUnderscore(Utils::trimNamespace($entityClass)); if (array_key_exists($table, $repositories)) { throw new \Exception(sprintf('Multiple repositories for table %s found.', $table)); } $repositories[$table] = $repositoryClass; } } return $repositories; }
/** * App\Repository\SomeEntityRepository -> some_entity * @param string $repositoryClass * @return string */ public function getTableByRepositoryClass($repositoryClass) { $class = preg_replace('#([a-z0-9]+)Repository$#', '$1', $repositoryClass); return Utils::camelToUnderscore($this->trimNamespace($class)); }