/** * Initializes the plugin autoloader. */ public function beforeCompile() { foreach ($this->containerBuilder->parameters['plugins'] as $definition) { $this->loader->addDirectory($definition['location']); } $this->loader->register(); }
/** @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; }
/** @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; }
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; }
/** * Autoloader php classes. * @param string|array * @param string * @return RobotLoader */ public function createAutoload($path) { $loader = new RobotLoader(); $loader->setCacheStorage(new FileStorage($this->temp)); $loader->addDirectory($path)->register(); return $loader; }
/** * Creates the configurator instance and prepares configuration cache. */ public function __construct(array $arguments) { parent::__construct(); $this->cache = new MemoryStorage(); $this->loader = new RobotLoader(); $this->loader->setCacheStorage($this->cache); $this->loader->autoRebuild = false; $this->arguments = $arguments; }
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; }
/** * @param array $dirs * @return Nette\Loaders\RobotLoader */ public static function createRobotLoader($dirs = array()) { if (!is_array($dirs)) { $dirs = func_get_args(); } $loader = new Nette\Loaders\RobotLoader(); $loader->setCacheStorage(new Nette\Caching\Storages\FileStorage(TEMP_DIR)); $loader->autoRebuild = TRUE; foreach ($dirs as $dir) { $loader->addDirectory($dir); } return $loader->register(); }
/** * * @param string|string[] $dirs absolute paths to directories for robot loading * @return RobotLoader */ public static function createRobotLoader($dirs = []) { if (!is_array($dirs)) { $dirs = func_get_args(); } $loader = new RobotLoader(); $loader->setCacheStorage(new FileStorage(TEMP_DIR)); $loader->autoRebuild = true; foreach ($dirs as $dir) { $loader->addDirectory($dir); } return $loader->register(); }
public static function initialize() { if (self::$initialized) { throw new \Exception("Already initialized"); } $loader = new RobotLoader(); $loader->addDirectory(__DIR__ . "/../../app")->addDirectory(__DIR__); $loader->setCacheStorage(new MemoryStorage()); $loader->register(); $container = (require __DIR__ . "/../../app/bootstrap.php"); $container->removeService("nette.userStorage"); $container->addService("nette.userStorage", new \DummyUserStorage()); self::$container = $container; }
/** * Create route list * @param string|null $module * @return ResourceRouteList */ public final function create($module = NULL) { $routeList = new ResourceRouteList($module ? $module : $this->module); foreach ($this->loader->getIndexedClasses() as $class => $file) { try { self::getClassReflection($class); } catch (InvalidStateException $e) { continue; } $methods = $this->getClassMethods($class); $routeData = $this->parseClassRoutes($methods); $this->addRoutes($routeList, $routeData, $class); } return $routeList; }
/** * 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; }
public function getIndexedClasses() { if (!$this->initialized) { $this->initialize(); } return parent::getIndexedClasses(); }
/** * Enable robotLoader. * @return Configurator */ public function enableLoader() { $this->robotLoader = $this->createRobotLoader(); $this->robotLoader->ignoreDirs .= ', tests, test, resources'; $this->robotLoader->addDirectory($this->parameters['appDir'])->register(); return $this; }
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; }
public function loadConfiguration() { $config = $this->_getConfig(); $builder = $this->getContainerBuilder(); foreach ($config['dirs'] as $namespace => $dir) { if (is_dir($dir)) { foreach (Finder::findFiles('*.php')->in($dir) as $key => $file) { $class = $file->getBasename('.php'); $refletion = new \ReflectionClass("{$namespace}\\{$class}"); if (in_array($refletion->getName(), $config['skip'])) { continue; } if ($refletion->isInstantiable()) { $builder->addDefinition($class)->setClass($refletion->getName()); } } } } if (!empty($config['interfaces'])) { $interfaces = array_keys($config['interfaces']); $loader = new Nette\Loaders\RobotLoader(); $loader->setCacheStorage($config['cache']); foreach ($config['interfaces'] as $dir) { if (is_dir($dir)) { $loader->addDirectory($dir); } } $loader->register(); foreach ($loader->getIndexedClasses() as $class => $file) { if (empty(array_intersect(class_implements($class), $interfaces))) { continue; } $refletion = new \ReflectionClass($class); if ($refletion->isInstantiable()) { $builder->addDefinition($class)->setClass($class); } } } }
private function loadDefinitions(ContainerBuilder $builder) { $classes = $this->robotLoader->getIndexedClasses(); $markerInterface = new ClassType(IServiceMarker::class); foreach ($classes as $key => $val) { if (Strings::endsWith($key, 'Service')) { $reflection = new ClassType($key); $serviceName = '_auto.' . str_replace("\\", "_", $key); if (!$reflection->isAbstract() && $reflection->isSubclassOf($markerInterface)) { $builder->addDefinition($serviceName)->setClass($key); } } } }
<?php define('LIBS_DIR', __DIR__ . '/../libs'); require_once LIBS_DIR . '/Nette/loader.php'; require_once LIBS_DIR . '/dump.php'; use Nette\Diagnostics\Debugger as Debug; use Nette\Environment; use Nette\Loaders\RobotLoader; Debug::enable(false); Debug::$strictMode = true; Environment::setVariable('tempDir', __DIR__ . '/tmp'); $r = new RobotLoader(); $r->setCacheStorage(Environment::getContext()->cacheStorage); $r->addDirectory(LIBS_DIR); $r->addDirectory(__DIR__ . '/cases'); $r->register(); require_once __DIR__ . '/TestCase.php';
<?php use Nette\Caching\Storages\DevNullStorage; use Nette\Loaders\RobotLoader; use Tester\Environment; require __DIR__ . '/../vendor/autoload.php'; Environment::setup(); $loader = new RobotLoader(); $loader->addDirectory(__DIR__ . '/../src'); $loader->setCacheStorage(new DevNullStorage()); $loader->register();
/** * @return array of class => filename */ public function getClasses() { $loader = new Nette\Loaders\RobotLoader(); $loader->setCacheStorage(new Nette\Caching\Storages\FileStorage($this->defaults['tempDir'])); $loader->addDirectory($this->defaults["appDir"]); $loader->register(); return $loader->getIndexedClasses(); }
/** * @return Nette\Loaders\RobotLoader */ public static function createServiceRobotLoader(DI\Container $container, array $options = NULL) { $loader = new Nette\Loaders\RobotLoader(); $loader->autoRebuild = isset($options['autoRebuild']) ? $options['autoRebuild'] : !$container->params['productionMode']; $loader->setCacheStorage($container->cacheStorage); if (isset($options['directory'])) { $loader->addDirectory($options['directory']); } else { foreach (array('appDir', 'libsDir') as $var) { if (isset($container->params[$var])) { $loader->addDirectory($container->params[$var]); } } } $loader->register(); return $loader; }
<?php namespace Achse\Tests; require __DIR__ . '/../vendor/autoload.php'; use Achse\PetrHejna\I18n\Locale; use Nette\Caching\Storages\FileStorage; use Nette\Loaders\RobotLoader; use Tester\Environment; if (!class_exists('Tester\\Assert')) { echo "Install Nette Tester using `composer update --dev`\n"; exit(1); } /** @var string[] $dirs */ $dirs = ['../app', '../libs', '../tests']; $loader = new RobotLoader(); $loader->setCacheStorage(new FileStorage(__DIR__ . '/tmp')); foreach ($dirs as $dir) { $loader->addDirectory(__DIR__ . '/' . $dir); } $loader->register(); date_default_timezone_set(Locale::DEFAULT_TIMEZONE); Environment::setup();
/** * @return Nette\Loaders\RobotLoader */ public static function createRobotLoader($options) { $loader = new Nette\Loaders\RobotLoader(); $loader->autoRebuild = !Environment::isProduction(); //$loader->setCache(Environment::getCache('Nette.RobotLoader')); $dirs = isset($options['directory']) ? $options['directory'] : array(Environment::getVariable('appDir'), Environment::getVariable('libsDir')); $loader->addDirectory($dirs); $loader->register(); return $loader; }
/** * @return Nette\Loaders\RobotLoader * @throws Nette\NotSupportedException if RobotLoader is not available */ public function createRobotLoader() { if (!class_exists('Nette\\Loaders\\RobotLoader')) { throw new Nette\NotSupportedException('RobotLoader not found, do you have `nette/robot-loader` package installed?'); } $loader = new Nette\Loaders\RobotLoader(); $loader->setCacheStorage(new Nette\Caching\Storages\FileStorage($this->getCacheDirectory())); $loader->autoRebuild = $this->parameters['debugMode']; return $loader; }
/** * @return Nette\Loaders\RobotLoader */ public function createRobotLoader() { if (!($cacheDir = $this->getCacheDirectory())) { throw new Nette\InvalidStateException("Set path to temporary directory using setTempDirectory()."); } $loader = new Nette\Loaders\RobotLoader(); $loader->setCacheStorage(new Nette\Caching\Storages\FileStorage($cacheDir)); $loader->autoRebuild = !$this->parameters['productionMode']; return $loader; }
/** * @return Nette\Loaders\RobotLoader */ public static function createRobotLoader($options) { $loader = new Nette\Loaders\RobotLoader(); $loader->autoRebuild = isset($options['autoRebuild']) ? $options['autoRebuild'] : !Environment::isProduction(); $loader->setCacheStorage(Environment::getService('Nette\\Caching\\ICacheStorage')); if (isset($options['directory'])) { $loader->addDirectory($options['directory']); } else { foreach (array('appDir', 'libsDir') as $var) { if ($dir = Environment::getVariable($var, NULL)) { $loader->addDirectory($dir); } } } $loader->register(); return $loader; }
<?php use Nette\Caching\Storages\FileStorage; use Nette\Loaders\RobotLoader; use Tracy\Debugger; use VersionPress\DI\DIContainer; use VersionPress\DI\VersionPressServices; define('VERSIONPRESS_PLUGIN_DIR', __DIR__); define('VERSIONPRESS_MIRRORING_DIR', WP_CONTENT_DIR . '/vpdb'); define('VERSIONPRESS_TEMP_DIR', VERSIONPRESS_PLUGIN_DIR . '/temp'); define('VERSIONPRESS_ACTIVATION_FILE', VERSIONPRESS_MIRRORING_DIR . '/.active'); require_once VERSIONPRESS_PLUGIN_DIR . '/versionpress-functions.php'; if (defined('DOING_AJAX')) { header("Content-Type: application/json"); } Debugger::enable(Debugger::DEVELOPMENT, VERSIONPRESS_PLUGIN_DIR . '/log'); $robotLoader = new RobotLoader(); $robotLoader->addDirectory(VERSIONPRESS_PLUGIN_DIR . '/src'); $robotLoader->setCacheStorage(new FileStorage(VERSIONPRESS_PLUGIN_DIR . '/temp')); $robotLoader->register(); global $versionPressContainer; $versionPressContainer = DIContainer::getConfiguredInstance();
/** * @return Nette\Loaders\RobotLoader */ public function createRobotLoader() { $loader = new Nette\Loaders\RobotLoader(); $loader->setCacheStorage(new Nette\Caching\Storages\FileStorage($this->getCacheDirectory())); $loader->autoRebuild = $this->parameters['debugMode']; return $loader; }
protected static function addRobotLoaderPaths(RobotLoader $loader) { $loader->addDirectory(static::$appDir)->addDirectory(static::$testsDir); }