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; }
/** @return string[] */ private function findPresenters() { $config = $this->getConfig(); $classes = array(); if ($config['scanDirs']) { $robot = new Nette\Loaders\RobotLoader(); $robot->setCacheStorage(new Nette\Caching\Storages\DevNullStorage()); $robot->addDirectory($config['scanDirs']); $robot->acceptFiles = '*' . $config['scanFilter'] . '*.php'; $robot->rebuild(); $classes = array_keys($robot->getIndexedClasses()); } if ($config['scanComposer']) { $rc = new \ReflectionClass('Composer\\Autoload\\ClassLoader'); $classFile = dirname($rc->getFileName()) . '/autoload_classmap.php'; if (is_file($classFile)) { $this->getContainerBuilder()->addDependency($classFile); $classes = array_merge($classes, array_keys(call_user_func(function ($path) { return require $path; }, $classFile))); } } $presenters = array(); foreach (array_unique($classes) as $class) { if (strpos($class, $config['scanFilter']) !== FALSE && class_exists($class) && ($rc = new \ReflectionClass($class)) && $rc->implementsInterface('Nette\\Application\\IPresenter') && !$rc->isAbstract()) { $presenters[] = $rc->getName(); } } return $presenters; }
/** @return string[] */ private function findPresenters() { $config = $this->getConfig(); $classes = []; if ($config['scanDirs']) { if (!class_exists(Nette\Loaders\RobotLoader::class)) { throw new Nette\NotSupportedException("RobotLoader is required to find presenters, install package `nette/robot-loader` or disable option {$this->prefix('scanDirs')}: false"); } $robot = new Nette\Loaders\RobotLoader(); $robot->setCacheStorage(new Nette\Caching\Storages\DevNullStorage()); $robot->addDirectory($config['scanDirs']); $robot->acceptFiles = '*' . $config['scanFilter'] . '*.php'; $robot->rebuild(); $classes = array_keys($robot->getIndexedClasses()); $this->getContainerBuilder()->addDependency($this->tempFile); } if ($config['scanComposer']) { $rc = new \ReflectionClass(ClassLoader::class); $classFile = dirname($rc->getFileName()) . '/autoload_classmap.php'; if (is_file($classFile)) { $this->getContainerBuilder()->addDependency($classFile); $classes = array_merge($classes, array_keys(call_user_func(function ($path) { return require $path; }, $classFile))); } } $presenters = []; foreach (array_unique($classes) as $class) { if (strpos($class, $config['scanFilter']) !== FALSE && class_exists($class) && ($rc = new \ReflectionClass($class)) && $rc->implementsInterface(Nette\Application\IPresenter::class) && !$rc->isAbstract()) { $presenters[] = $rc->getName(); } } return $presenters; }
protected function getFiles($directory) { $robot = new RobotLoader(); $robot->addDirectory($directory); $robot->setCacheStorage(new MemoryStorage()); $robot->rebuild(); $indexed = array_keys($robot->getIndexedClasses()); return $indexed; }
public function createForDirectory(string $directory) : RobotLoader { $robot = new RobotLoader(); $robot->setCacheStorage(new DevNullStorage()); $robot->addDirectory($directory); $robot->ignoreDirs .= ', tests, Tests'; $robot->acceptFiles = '*Sniff.php'; $robot->rebuild(); return $robot; }
/** * Find all sitemap classes * * @return string[] Class names */ public function findClasses() { // find all classes $robot = new RobotLoader(); foreach ($this->dirs as $dir) { if (!is_dir($dir)) { continue; } $robot->addDirectory($dir); } $robot->setCacheStorage(new \Nette\Caching\Storages\DevNullStorage()); $robot->rebuild(); $classes = array_keys($robot->getIndexedClasses()); return $classes; }
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('LeanMapper\\Repository') && !$rc->isAbstract()) { $repositories[] = $rc->getName(); } } return $repositories; }