저자: David Grudl
상속: extends nette\Object
 /**
  * @return Container
  */
 public function create()
 {
     $configurator = new Configurator();
     $configurator->setTempDirectory(TEMP_DIR);
     $configurator->addConfig(__DIR__ . '/config/default.neon');
     return $configurator->createContainer();
 }
예제 #2
0
파일: ShoPHP.php 프로젝트: shophp/shophp
 public static function initialize(Configurator $configurator)
 {
     $configurator->addConfig(__DIR__ . '/config/base.neon');
     $configurator->addConfig(__DIR__ . '/config/routes.neon');
     $configurator->addConfig(__DIR__ . '/config/services.neon');
     $configurator->addConfig(__DIR__ . '/config/presenters.neon');
 }
예제 #3
0
 /**
  * @param Configurator $configurator
  */
 protected function loadConfigFiles(Configurator $configurator)
 {
     if ($this->autoloadConfig === TRUE || is_array($this->autoloadConfig)) {
         $scanDirs = $this->autoloadConfig === TRUE ? [$this->appDir] : $this->autoloadConfig;
         $cache = $this->createCache();
         $files = $cache->load(self::CACHE_NAMESPACE);
         if ($files === NULL) {
             $files = [0 => []];
             foreach (Finder::findFiles('*.neon')->from($scanDirs) as $path => $file) {
                 $content = Neon::decode(file_get_contents($path));
                 if (!is_array($content) || !array_key_exists('autoload', $content)) {
                     continue;
                 }
                 $autoload = Arrays::get($content, ['autoload', 0], FALSE);
                 if ($autoload === FALSE) {
                     continue;
                 }
                 $autoload = is_int($autoload) ? $autoload : 0;
                 if (!isset($files[$autoload])) {
                     $files[$autoload] = [];
                 }
                 $files[$autoload][] = $path;
             }
             $cache->save(self::CACHE_NAMESPACE, $files);
         }
         foreach ($files as $priorityFiles) {
             foreach ($priorityFiles as $config) {
                 $configurator->addConfig($config);
             }
         }
     }
     foreach ($this->configs as $config) {
         $configurator->addConfig($config);
     }
 }
예제 #4
0
 protected function createContainer()
 {
     $configurator = new Configurator();
     $configurator->addParameters(array('wwwDir' => $this->wwwDir));
     $configurator->setTempDirectory(TEMP_DIR);
     $configurator->addConfig(__DIR__ . '/../config.neon');
     return $configurator->createContainer();
 }
예제 #5
0
 protected function createContainer()
 {
     $configurator = new Configurator();
     $configurator->setDebugMode(FALSE);
     $configurator->setTempDirectory(TEMP_DIR);
     $configurator->addConfig(__DIR__ . '/../config.neon');
     return $configurator->createContainer();
 }
예제 #6
0
 /**
  * @return Nette\Configurator
  */
 protected function doCreateConfiguration()
 {
     $config = new Nette\Configurator();
     $config->addParameters(['rootDir' => $rootDir = dirname(dirname(dirname(dirname(__DIR__)))), 'appDir' => $rootDir . '/app', 'wwwDir' => $rootDir . '/www']);
     // shared compiled container for faster tests
     $config->setTempDirectory(dirname(TEMP_DIR));
     return $config;
 }
 public function create() : Container
 {
     $configurator = new Configurator();
     $configurator->setDebugMode(true);
     $configurator->setTempDirectory($this->createAndReturnTempDir());
     $configurator->addConfig(__DIR__ . '/../config/config.neon');
     return $configurator->createContainer();
 }
예제 #8
0
 /**
  * Create new DI container.
  */
 protected function createContainer()
 {
     // Create bootstrap configurator
     $config = new Configurator();
     $config->setTempDirectory(sys_get_temp_dir());
     $config->addConfig(__DIR__ . '/../Helpers/config.neon');
     // Create DI container
     return $config->createContainer();
 }
 /**
  * @return Configurator
  */
 protected function createConfigurator()
 {
     // /vendor/meridius/tester-extras/src/Meridius/TesterExtras/
     $rootDir = __DIR__ . '/../../../../../..';
     $config = new Configurator();
     $config->addParameters(['rootDir' => $rootDir, 'appDir' => $rootDir . '/app', 'wwwDir' => $rootDir . '/www']);
     // shared compiled container for faster tests
     $config->setTempDirectory(dirname(TEMP_DIR));
     return $config;
 }
예제 #10
0
 /**
  * @param bool $debugMode
  * @return Nette\DI\Container
  */
 protected function createContainer($debugMode)
 {
     $config = new Nette\Configurator();
     $config->setTempDirectory(TEMP_DIR);
     $config->setDebugMode($debugMode);
     Debugger::$productionMode = !$debugMode;
     QueryPanelExtension::register($config);
     $config->addConfig(__DIR__ . '/config.neon');
     return $config->createContainer();
 }
 /**
  * @return Container
  */
 public function createContainer()
 {
     $config = new Configurator();
     $config->setTempDirectory($this->temporaryDirectory);
     $config->addParameters($this->parameters);
     foreach ($this->configurationFiles as $file => $section) {
         $config->addConfig($file, $section);
     }
     return $config->createContainer();
 }
예제 #12
0
 /**
  * @return \SystemContainer|\Nette\DI\Container
  */
 protected function createContainer()
 {
     $config = new Configurator();
     $config->setTempDirectory(TEMP_DIR);
     $cronExtension = $this->extension;
     $config->onCompile[] = function ($config, Compiler $compiler) use($cronExtension) {
         $compiler->addExtension('cron', $cronExtension);
     };
     $config->addConfig(__DIR__ . '/config.neon');
     return $config->createContainer();
 }
예제 #13
0
 public function __construct(Configurator $configurator, Nette\DI\Container $context, DibiConnection $dibi)
 {
     parent::__construct();
     $this->addParameter('createOrm', function () use($configurator, $context, $dibi) {
         $orm = $configurator->createServiceOrm($context);
         $orm->getContext()->removeService('performanceHelperCache')->removeService('dibiConnection')->addService('dibiConnection', $dibi);
         return $orm;
     });
     $this->addParameter('context', $context);
     $this->addParameter('dibi', $dibi);
 }
예제 #14
0
 /**
  * @return Kdyby\Doctrine\EntityManager
  */
 protected function createMemoryManager()
 {
     $rootDir = __DIR__ . '/../../';
     $config = new Nette\Configurator();
     $container = $config->setTempDirectory(TEMP_DIR)->addConfig(__DIR__ . '/../nette-reset.neon')->addConfig(__DIR__ . '/config/memory.neon')->addParameters(array('appDir' => $rootDir, 'wwwDir' => $rootDir))->createContainer();
     /** @var Nette\DI\Container $container */
     $em = $container->getByType('Kdyby\\Doctrine\\EntityManager');
     /** @var Kdyby\Doctrine\EntityManager $em */
     $schemaTool = new SchemaTool($em);
     $schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
     $this->serviceLocator = $container;
     return $em;
 }
예제 #15
0
 /**
  * @param $configFile
  * @return Nette\DI\Container
  */
 public static function createContainer($configFile = NULL)
 {
     $configurator = new Nette\Configurator();
     $configurator->setTempDirectory(TEMP_DIR);
     $configurator->addParameters(array('fixturesDir' => FIXTURES_DIR, 'tempDir' => TEMP_DIR, 'wwwDir' => TEMP_DIR));
     if ($configFile !== NULL) {
         $configurator->addConfig($configFile);
     }
     $extension = new Extension();
     $extension->register($configurator, 'tidy');
     $container = $configurator->createContainer();
     return $container;
 }
예제 #16
0
 /**
  * @param Nette\Configurator $configurator
  * @return bool has the debug mode been modified?
  */
 public static function setupMode(Nette\Configurator $configurator)
 {
     if (PHP_SAPI !== 'cli') {
         return FALSE;
     }
     $input = new ArgvInput();
     if (!$input->hasParameterOption('--debug-mode')) {
         return FALSE;
     }
     if ($input->hasParameterOption(['--debug-mode=no', '--debug-mode=off', '--debug-mode=false', '--debug-mode=0'])) {
         $configurator->setDebugMode(FALSE);
         return TRUE;
     } else {
         $configurator->setDebugMode(TRUE);
         return TRUE;
     }
 }
예제 #17
0
 /**
  * @param $configFile
  * @return Nette\DI\Container
  */
 public static function createContainer($configFile = NULL)
 {
     $configurator = new Nette\Configurator();
     $configurator->setTempDirectory(TEMP_DIR);
     $configurator->addParameters(array('fixturesDir' => FIXTURES_DIR, 'tempDir' => TEMP_DIR, 'wwwDir' => TEMP_DIR));
     if ($configFile !== NULL) {
         $configurator->addConfig($configFile);
     }
     $extension = new Extension();
     $extension->register($configurator, 'assetic');
     $container = $configurator->createContainer();
     /** @var Nette\Http\IRequest $httpRequest */
     $httpRequest = $container->getByType('Nette\\Http\\IRequest');
     $httpRequest->getUrl()->setHost('localhost');
     // with empty host not work properly
     echo "tempDir: " . TEMP_DIR . PHP_EOL;
     return $container;
 }
예제 #18
0
 /**
  * @return Nette\Loaders\RobotLoader
  */
 public function createRobotLoader()
 {
     if ($this->robotLoader === NULL) {
         $loader = parent::createRobotLoader();
         $loader->addDirectory($this->parameters['packagesDir']);
         $this->robotLoader = $loader;
     }
     return $this->robotLoader;
 }
 protected function createContainer()
 {
     $configurator = new Nette\Configurator();
     $configurator->setTempDirectory(dirname(TEMP_DIR));
     // shared container for performance purposes
     $configurator->setDebugMode(FALSE);
     $configurator->addParameters(['appDir' => __DIR__ . '/../../app']);
     $configurator->addConfig(__DIR__ . '/../../app/config/config.neon');
     $configurator->addConfig(__DIR__ . '/../../app/config/' . getenv('DB') . '.neon');
     $configurator->addConfig(__DIR__ . '/../config/tests.neon');
     return $configurator->createContainer();
 }
예제 #20
0
 /**
  * @param Configurator
  * @return void
  */
 protected function setupConfiguration(Configurator $configurator)
 {
     if ($this->options->getPrimaryConfig() !== NULL) {
         $configurator->addConfig($this->options->getPrimaryConfig()->getFile());
     }
     if ($this->options->getLocalConfig() !== NULL && Helpers::detectDevelopmentEnvironment()) {
         $configurator->addConfig($this->options->getLocalConfig()->getFile());
     }
     foreach ($this->options->getConfigs() as $config) {
         $configurator->addConfig($config->getFile());
     }
 }
예제 #21
0
 /**
  * @param $configFile
  * @return Nette\DI\Container
  */
 public static function createContainer($configFile = NULL)
 {
     $configurator = new Nette\Configurator();
     $configurator->setTempDirectory(TEMP_DIR);
     $configurator->addParameters(array('fixturesDir' => FIXTURES_DIR, 'tempDir' => TEMP_DIR, 'appDir' => __DIR__ . '/../../app', 'wwwDir' => WWW_DIR, 'vendorDir' => __DIR__ . '/../../vendor'));
     $configurator->addConfig(__DIR__ . '/../../app/config/_config.neon');
     $configurator->addConfig(__DIR__ . '/../../app/config/_dev.neon');
     $configurator->addConfig(__DIR__ . '/../config.tests.neon');
     if ($configFile !== NULL) {
         $configurator->addConfig($configFile);
     }
     $extension = new Extension();
     $extension->register($configurator, 'assetic');
     $container = $configurator->createContainer();
     /** @var Nette\Http\IRequest $httpRequest */
     $httpRequest = $container->getByType('Nette\\Http\\IRequest');
     $httpRequest->getUrl()->setHost('localhost');
     // with empty host not work properly
     return $container;
 }
예제 #22
0
 /**
  * @param string|null $customConfig
  * @return \Nette\DI\Container
  */
 protected function createContainer($customConfig = null)
 {
     if (!$this->context) {
         $config = new Configurator();
         $config->setTempDirectory(TEMP_DIR);
         $config->addParameters(['appDir' => __DIR__ . '/app']);
         $config->addConfig(__DIR__ . '/app/config/config.neon');
         if ($customConfig) {
             $config->addConfig(FileMock::create($customConfig, 'neon'));
         }
         $this->context = $config->createContainer();
     }
     return $this->context;
 }
예제 #23
0
 /**
  * @param null|string $configFile
  * @param bool $defaultConfig
  * @return Nette\DI\Container|\SystemContainer
  */
 public static function createContainer($configFile = NULL, $defaultConfig = TRUE)
 {
     // create temporary directory
     $tempDir = __DIR__ . '/../temp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()) . Nette\Utils\Random::generate();
     Tester\Helpers::purge($tempDir);
     $configurator = new Nette\Configurator();
     $configurator->setTempDirectory($tempDir);
     $configurator->addParameters(array('container' => array('class' => 'SystemContainer_' . md5(time())), 'fixturesDir' => FIXTURES_DIR, 'tempDir' => $tempDir, 'wwwDir' => $tempDir));
     $configurator->addConfig(__DIR__ . '/../nette-reset.neon');
     if ($defaultConfig === TRUE) {
         $configurator->addConfig(__DIR__ . '/../config.neon');
     }
     if ($configFile !== NULL) {
         $configurator->addConfig($configFile);
     }
     $container = $configurator->createContainer();
     /** @var Nette\Http\IRequest $httpRequest */
     $httpRequest = $container->getByType('Nette\\Http\\IRequest');
     $httpRequest->getUrl()->setHost('localhost');
     // with empty host not work properly
     $ems = $container->findByType('Doctrine\\ORM\\EntityManager');
     if (count($ems) === 1) {
         /** @var EntityManager $em */
         $em = $container->getService($ems[0]);
         $schemaTool = new SchemaTool($em);
         $schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
     }
     $dms = $container->findByType('Doctrine\\ODM\\MongoDB\\DocumentManager');
     if (count($dms) === 1) {
         /** @var DocumentManager $dm */
         $dm = $container->getService($dms[0]);
         $dm->getSchemaManager()->createDatabases();
         $dm->getSchemaManager()->createCollections();
     }
     return $container;
 }
 /**
  * Creates RobotLoader and unregisters Nette's original inject extension.
  *
  * @param Configurator $configurator
  * @param string $robotLoaderDir
  */
 public static function bootstrapTweak(Configurator $configurator, $robotLoaderDir)
 {
     self::$staticRobotLoader = $configurator->createRobotLoader()->addDirectory($robotLoaderDir)->register();
     unset($configurator->defaultExtensions['inject']);
 }
예제 #25
0
 /**
  * @param Configurator $configurator
  * @return DIContainer
  */
 protected function createContainer(Configurator $configurator)
 {
     $container = $configurator->createContainer();
     return $container;
 }
예제 #26
0
 /**
  * Loads global configuration from file and process it.
  * @param  string
  * @param  string
  * @return Nette\Utils\ArrayHash
  */
 public static function loadConfig($file = NULL, $section = NULL)
 {
     if (self::$createdAt) {
         throw new Nette\InvalidStateException('Nette\\Configurator has already been created automatically by Nette\\Environment at ' . self::$createdAt);
     } elseif (!defined('TEMP_DIR')) {
         throw new Nette\InvalidStateException('Nette\\Environment requires constant TEMP_DIR with path to temporary directory.');
     }
     $configurator = new Nette\Configurator();
     $configurator->setDebugMode(!self::isProduction())->setTempDirectory(TEMP_DIR)->addParameters(array('container' => array('class' => 'EnvironmentContainer')));
     if ($file) {
         $configurator->addConfig($file, $section);
     }
     self::$context = $configurator->createContainer();
     self::$createdAt = '?';
     foreach (debug_backtrace(FALSE) as $row) {
         if (isset($row['file']) && $row['file'] !== __FILE__ && is_file($row['file'])) {
             self::$createdAt = "{$row['file']}:{$row['line']}";
             break;
         }
     }
     return self::getConfig();
 }
예제 #27
0
 public function __construct()
 {
     parent::__construct();
     $this->parameters = $this->parameters();
     $this->defaultExtensions += ['dirs' => 'Drago\\Directory\\DirsExtension'];
 }
예제 #28
0
<?php

namespace NetteAddons;

use Nette\Configurator;
// Load Nette Framework or autoloader generated by Composer
require __DIR__ . '/../vendor/autoload.php';
$configurator = new Configurator();
// Enable Nette Debugger for error visualisation & logging
//$configurator->setDebugMode(TRUE);
$configurator->enableDebugger(__DIR__ . '/../log');
// Specify folder for cache
$configurator->setTempDirectory(__DIR__ . '/../temp');
// Enable RobotLoader - this will load all classes automatically
$configurator->createRobotLoader()->addDirectory(__DIR__)->register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
$container = $configurator->createContainer();
return $container;
예제 #29
0
 /**
  * Pre-expands %placeholders% in string.
  * @internal
  */
 public static function preExpand($s, array $params, $check = array())
 {
     if (!is_string($s)) {
         return $s;
     }
     $parts = preg_split('#%([\\w.-]*)%#i', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
     $res = '';
     foreach ($parts as $n => $part) {
         if ($n % 2 === 0) {
             $res .= str_replace('%', '%%', $part);
         } elseif ($part === '') {
             $res .= '%%';
         } elseif (isset($check[$part])) {
             throw new Nette\InvalidArgumentException('Circular reference detected for variables: ' . implode(', ', array_keys($check)) . '.');
         } else {
             try {
                 $val = Nette\Utils\Arrays::get($params, explode('.', $part));
             } catch (Nette\InvalidArgumentException $e) {
                 $res .= "%{$part}%";
                 continue;
             }
             $val = self::preExpand($val, $params, $check + array($part => 1));
             if (strlen($part) + 2 === strlen($s)) {
                 if (is_array($val)) {
                     array_walk_recursive($val, function (&$val) use($params, $check, $part) {
                         $val = Configurator::preExpand($val, $params, $check + array($part => 1));
                     });
                 }
                 return $val;
             }
             if (!is_scalar($val)) {
                 throw new Nette\InvalidArgumentException("Unable to concatenate non-scalar parameter '{$part}' into '{$s}'.");
             }
             $res .= $val;
         }
     }
     return $res;
 }
예제 #30
0
 /**
  * @throws MissingLocalConfigException
  * @throws \Exception
  * @throws \Nette\FileNotFoundException
  * @return Container
  */
 public function createContainer()
 {
     $this->onInit($this);
     $this->onInit = [];
     try {
         $container = parent::createContainer();
         $this->onAfter($container);
         return $container;
     } catch (FileNotFoundException $e) {
         if (strpos($e->getMessage(), 'local') !== FALSE) {
             throw new MissingLocalConfigException($e);
         } else {
             throw $e;
         }
     }
 }