addDirectory() public method

Add path or paths to list.
public addDirectory ( $path ) : self
return self
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * 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('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;
 }
Beispiel #5
0
 /**
  * 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;
 }
 /** @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;
 }
 protected function getFiles($directory)
 {
     $robot = new RobotLoader();
     $robot->addDirectory($directory);
     $robot->setCacheStorage(new MemoryStorage());
     $robot->rebuild();
     $indexed = array_keys($robot->getIndexedClasses());
     return $indexed;
 }
Beispiel #8
0
 /**
  * @param string $presentersRoot from where to find presenters
  * @param IStorage $cacheStorage
  * @param RouteAnnotation $routeAnnotation
  */
 public function __construct($presentersRoot, IStorage $cacheStorage, RouteAnnotation $routeAnnotation)
 {
     $loader = new RobotLoader();
     $loader->addDirectory($presentersRoot);
     $loader->setCacheStorage($cacheStorage);
     $loader->tryLoad('Drahak\\Restful\\Application\\IResourcePresenter');
     $this->loader = $loader;
     $this->cacheStorage = $cacheStorage;
     $this->routeAnnotation = $routeAnnotation;
 }
 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;
 }
Beispiel #10
0
 /**
  * @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();
 }
Beispiel #11
0
 /**
  *
  * @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();
 }
Beispiel #12
0
 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;
 }
Beispiel #13
0
 /**
  * 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;
 }
 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);
             }
         }
     }
 }
Beispiel #16
0
 /**
  * @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;
 }
Beispiel #17
0
<?php

use Nette\Debug, Nette\Environment, Nette\Loaders\RobotLoader;
// Step 1: Load Nette Framework
// this allows load Nette Framework classes automatically so that
// you don't have to litter your code with 'require' statements
// require LIBS_DIR . '/Nette/loader.php';
require __DIR__ . '/../../../Nette/loader.php';
// Step 2: Configure environment
// 2a) enable Nette\Debug for better exception and error visualisation
Debug::enable();
// 2b) enable RobotLoader - this allows load all classes automatically
$loader = new RobotLoader();
$loader->addDirectory(APP_DIR);
$loader->register();
// Step 3: Configure application
$application = Environment::getApplication();
// Step 4: Run the application!
$application->run();
Beispiel #18
0
 /**
  * @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;
 }
Beispiel #19
0
 public function enableRobotLoader()
 {
     $this->robotLoader = $this->createRobotLoader();
     $this->robotLoader->addDirectory($this->parameters['appDir'])->register();
 }
Beispiel #20
0
<?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();
 protected static function addRobotLoaderPaths(RobotLoader $loader)
 {
     $loader->addDirectory(static::$appDir)->addDirectory(static::$testsDir);
 }
Beispiel #22
0
<?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';
Beispiel #23
0
 /**
  * @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;
 }
Beispiel #24
0
 /**
  * @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();
 }
<?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();
Beispiel #26
0
 public function handleInstall()
 {
     if ($this->connectionCheckerFactory->invoke() && count($this->getEntityManager()->getConnection()->getSchemaManager()->listTables()) == 0) {
         if ($this->backup) {
             $this->deploymentManager->loadBackup($this->backup);
         } else {
             /** @var $em \Doctrine\ORM\EntityManager */
             $em = $this->getEntityManager();
             $tool = new SchemaTool($em);
             $robotLoader = new RobotLoader();
             $robotLoader->setCacheStorage(new MemoryStorage());
             $robotLoader->addDirectory($this->context->parameters['modules']['cms']['path'] . '/CmsModule');
             $robotLoader->register();
             $classes = array();
             foreach ($robotLoader->getIndexedClasses() as $item => $a) {
                 $ref = ClassType::from($item);
                 if ($ref->hasAnnotation('ORM\\Entity')) {
                     $classes[] = $em->getClassMetadata('\\' . $item);
                 }
             }
             $tool->createSchema($classes);
             /** @var $installer CmsInstaller */
             $installer = $this->context->createInstance('CmsModule\\Module\\Installers\\CmsInstaller');
             $installer->install($this->context->venne->moduleManager->modules['cms']);
         }
     }
     $this->redirect('Installation:', array('backup' => NULL));
 }
Beispiel #27
0
<?php

use Nette\Diagnostics\Debugger, Nette\Loaders\RobotLoader, Nette\Caching\Storages\FileStorage;
if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    echo 'Install Nette Tester using `composer update --dev`';
    exit(1);
}
define('LOG_DIR', __DIR__ . '/log');
define('TEMP_DIR', __DIR__ . '/temp');
define('MOCKS_DIR', __DIR__ . '/Mocks');
define('ELERIUM_DIR', __DIR__ . '/../Elerium');
Debugger::$consoleMode = TRUE;
Debugger::$strictMode = TRUE;
Debugger::enable(Debugger::DEVELOPMENT, LOG_DIR);
$loader = new RobotLoader();
$loader->addDirectory(ELERIUM_DIR);
$loader->setCacheStorage(new FileStorage(TEMP_DIR));
$loader->register();
Beispiel #28
0
<?php

use Nette\Caching\Storages\FileStorage;
use Nette\Loaders\RobotLoader;
use Tester\Environment;
define('DIR_ROOT', __DIR__ . '/..');
define('DIR_TEMP', DIR_ROOT . '/temp');
define('DIR_TESTS', __DIR__);
require_once DIR_ROOT . '/vendor/autoload.php';
$loader = new RobotLoader();
$loader->addDirectory(DIR_ROOT . '/src');
$loader->setCacheStorage(new FileStorage(DIR_TEMP));
$loader->register();
Environment::setup();
Beispiel #29
0
<?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();