Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public function getRelationshipTable($sourceTable, $targetTable)
 {
     $relationshipTable = sprintf('%s%s%s', Utils::trimTableSchema($sourceTable), $this->relationshipTableGlue, Utils::trimTableSchema($targetTable));
     return $this->defaultSchema ? sprintf('%s.%s', $this->defaultSchema, $relationshipTable) : $relationshipTable;
 }
Exemplo n.º 3
0
 /**
  * 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));
 }