저자: David Grudl
 /**
  * Processes configuration data. Intended to be overridden by descendant.
  *
  * @throws \Exception
  */
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $values = Nette\DI\Config\Helpers::merge($this->getConfig(), $this->defaults);
     $config = Nette\DI\Helpers::expand($values['paramsSettings'], $builder->parameters);
     unset($values['paramsSettings']);
     $db = NULL;
     if ($config['database'] !== FALSE) {
         $databaseClass = strpos($config['database'], '\\') ? $config['database'] : 'WebChemistry\\Parameters\\Database\\' . $config['database'];
         if (!class_exists($databaseClass)) {
             throw new \Exception("Class '{$databaseClass}' does not exist.");
         }
         $db = $builder->addDefinition($this->prefix('database'))->setClass('WebChemistry\\Parameters\\IDatabase')->setFactory($databaseClass);
         if ($config['database'] === 'Doctrine') {
             $implements = class_implements($config['entity']);
             if (array_search('WebChemistry\\Parameters\\IEntity', $implements) === FALSE) {
                 throw new ConfigurationException("Class '{$config['entity']}' must implements WebChemistry\\Parameters\\IEntity.");
             }
             $db->addSetup('setEntity', [$config['entity']]);
         }
     }
     $builder->addDefinition($this->prefix('provider'))->setClass('WebChemistry\\Parameters\\Provider', [$values, $config['cache'], $db]);
     if ($config['bar'] && class_exists('Tracy\\Debugger')) {
         $builder->addDefinition($this->prefix('bar'))->setClass('WebChemistry\\Parameters\\Bar\\Debug', [(bool) $db]);
     }
 }
예제 #2
0
 private function _getConfig()
 {
     $config = $this->validateConfig($this->defaults, $this->config);
     $config['log_directory'] = Nette\DI\Helpers::expand($config['log_directory'], $this->getContainerBuilder()->parameters);
     $config['mail_images_base_path'] = Nette\DI\Helpers::expand($config['mail_images_base_path'], $this->getContainerBuilder()->parameters);
     return $config;
 }
예제 #3
0
 private function setupCompileTemplatesCommand(ContainerBuilder $builder, array $config)
 {
     $config = $this->validateConfig($this->compileTemplatesDefaults, $config, 'compileTemplates');
     Validators::assertField($config, 'source', 'string|array');
     $builder->addDefinition($this->prefix('compileTemplates'))->setClass(CompileTemplatesCommand::class, [array_map(function ($directory) use($builder) {
         Validators::assert($directory, 'string');
         return Helpers::expand($directory, $builder->parameters);
     }, (array) $config['source'])])->addTag(ConsoleExtension::TAG_COMMAND)->setAutowired(false);
 }
예제 #4
0
 public function beforeCompile()
 {
     $builder = $this->getContainerBuilder();
     $this->validateConfig($this->defaults);
     $config = $this->getConfig($this->defaults);
     foreach ($builder->findByType('Nette\\Mail\\IMailer') as $name => $def) {
         $builder->removeDefinition($name);
     }
     $builder->addDefinition('fileMailer')->setClass(FileMailer::class, [$config])->addSetup('$tempDir', [Helpers::expand($config['tempDir'], $builder->parameters)]);
 }
 /**
  * @param Container $container
  * @param ManagerRegistry $registry
  */
 public function __construct(Container $container, ManagerRegistry $registry)
 {
     parent::__construct('dwarfSearch:import');
     $this->entityManager = $registry->getManager();
     $this->seasonsRepository = $registry->getRepository(Season::class);
     $this->episodesRepository = $registry->getRepository(Episode::class);
     $this->languagesRepository = $registry->getRepository(Language::class);
     $this->charactersRepository = $registry->getRepository(Character::class);
     $this->scenariosDir = Helpers::expand('%appDir%/../scenarios', $container->getParameters());
 }
 public function loadConfiguration()
 {
     // Cause we don't want merge arrays (annotations, interfaces, etc..)
     $config = $this->getCustomConfig($this->defaults);
     // Validate config
     Validators::assertField($config, 'dirs', 'array');
     Validators::assertField($config, 'annotations', 'array|null');
     Validators::assertField($config, 'interfaces', 'array|null');
     Validators::assertField($config, 'decorator', 'array');
     // Expand config (cause %appDir% etc..)
     $this->config = Helpers::expand($config, $this->getContainerBuilder()->parameters);
 }
예제 #7
0
 public function beforeCompile()
 {
     foreach ($this->getConfig() as $class => $info) {
         $info = $this->validateConfig($this->defaults, $info, $this->prefix($class));
         if ($info['inject'] !== NULL) {
             $info['tags'][InjectExtension::TAG_INJECT] = $info['inject'];
         }
         $info = Nette\DI\Helpers::filterArguments($info);
         $this->addSetups($class, (array) $info['setup']);
         $this->addTags($class, (array) $info['tags']);
     }
 }
예제 #8
0
 /**
  * @return array
  */
 public function getSettings()
 {
     if (method_exists($this, 'validateConfig')) {
         $config = $this->validateConfig($this->defaults, $this->config);
         $config['wwwDir'] = Nette\DI\Helpers::expand($config['wwwDir'], $this->getContainerBuilder()->parameters);
         $config['appDir'] = Nette\DI\Helpers::expand($config['appDir'], $this->getContainerBuilder()->parameters);
     } else {
         $config = $this->getConfig($this->defaults);
         // deprecated
     }
     return $config;
 }
예제 #9
0
 /**
  * Method setings extension.
  */
 public function beforeCompile()
 {
     $builder = $this->getContainerBuilder();
     $this->validateConfig($this->defaults);
     $config = $this->getConfig($this->defaults);
     foreach ($builder->findByType('Nette\\Mail\\IMailer') as $name => $def) {
         $builder->removeDefinition($name);
     }
     if ($config['debugger'] && interface_exists('Tracy\\IBarPanel')) {
         $builder->addDefinition($this->prefix('panel'))->setClass('RM\\MailPanel')->addSetup('$newMessageTime', [$config['newMessageTime']])->addSetup('$show', [array_unique($config['show'])])->addSetup('$autoremove', [$config['autoremove']])->addSetup('$hideEmpty', [$config['hideEmpty']]);
     }
     $builder->addDefinition($this->prefix('mailer'))->setClass('RM\\FileMailer', [Helpers::expand($config['tempDir'], $builder->parameters)])->addSetup('@RM\\MailPanel::setFileMailer', ['@self'])->addSetup('@Tracy\\Bar::addPanel', [$this->prefix('@panel')]);
 }
예제 #10
0
	/**
	 * @return Nette\Application\IResponse
	 */
	public function run(Application\Request $request)
	{
		$this->request = $request;

		if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
			$refUrl = clone $this->httpRequest->getUrl();
			$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
			if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) {
				return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
			}
		}

		$params = $request->getParameters();
		if (!isset($params['callback'])) {
			throw new Application\BadRequestException('Parameter callback is missing.');
		}
		$params['presenter'] = $this;
		$callback = $params['callback'];
		$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
		$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);

		if ($this->context) {
			foreach ($reflection->getParameters() as $param) {
				if ($param->getClassName()) {
					unset($params[$param->getPosition()]);
				}
			}

			$params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context);
			$params['presenter'] = $this;
		}

		$response = call_user_func_array($callback, $params);

		if (is_string($response)) {
			$response = array($response, array());
		}
		if (is_array($response)) {
			list($templateSource, $templateParams) = $response;
			$response = $this->createTemplate()->setParameters($templateParams);
			if (!$templateSource instanceof \SplFileInfo) {
				$response->getLatte()->setLoader(new Latte\Loaders\StringLoader);
			}
			$response->setFile($templateSource);
		}
		if ($response instanceof Application\UI\ITemplate) {
			return new Responses\TextResponse($response);
		} else {
			return $response;
		}
	}
예제 #11
0
 /**
  * @inheritDoc
  */
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = Helpers::expand($this->getConfig() + $this->defaults, $builder->parameters);
     $this->setupConfigByExtensions($config);
     $this->assertConfig($config);
     $builder->parameters[$this->prefix('debug')] = !empty($config['debug']);
     $this->createMetadataDriver();
     $this->createConfigurationService($config);
     $this->createEventManager($config);
     $this->createConnection($config);
     $this->createEntityManager($config);
     $this->registerMetadata($config['metadata']);
     $this->registerEventSubscribers($config['eventSubscribers']);
 }
 private function injectByProperties(Presenter $presenter)
 {
     if (class_exists(InjectExtension::class)) {
         /** @noinspection PhpInternalEntityUsedInspection */
         $properties = InjectExtension::getInjectProperties(get_class($presenter));
         // Nette 2.3+
     } else {
         $properties = Helpers::getInjectProperties(new ClassType($presenter));
         // Nette 2.2
     }
     foreach ($properties as $property => $type) {
         if (isset($this->dependencies['@' . $property])) {
             $presenter->{$property} = $this->dependencies['@' . $property];
         } elseif (isset($this->dependencies[$property])) {
             $presenter->{$property} = $this->dependencies[$property];
         }
     }
 }
예제 #13
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->validateConfig($this->defaults);
     // Add themes
     $params = [];
     $neon = new NeonAdapter();
     foreach (Finder::findFiles('theme.neon')->limitDepth(2)->from($config['themes']) as $file => $splfile) {
         // Parse config
         $expandConfig = ['themeDir' => dirname($splfile->getRealPath())];
         $themeConfig = Helpers::expand($neon->load($file), $expandConfig, TRUE);
         // Validate theme configs
         $this->validateConfig($this->themeDefaults, $themeConfig, 'themes');
         $this->validateConfig($this->themeDefaults['theme'], $themeConfig['theme'], 'theme');
         // Parse theme name
         $themeName = strtolower($themeConfig['theme']['name']);
         // Check duplicity
         if (array_key_exists($themeName, $params)) {
             throw new InvalidStateException('Theme "' . $themeName . '" is already defined.');
         }
         // Add to array
         $params[$themeName] = $themeConfig;
     }
     // Check if selected template is not null
     Validators::assertField($params, $config['theme'], NULL, 'template "%s"');
     $theme = $params[$config['theme']];
     // Add parameters to global parameters
     $builder->parameters['themes'] = [];
     $builder->parameters['themes']['theme'] = $theme['theme'];
     $builder->parameters['themes']['vars'] = $config['template'];
     $builder->parameters['themes']['output'] = $config['output'];
     // Add template model to container
     Compiler::parseServices($builder, ['services' => $theme['model']], $this->prefix('model'));
     // Add command manager (fake presenter)
     $builder->addDefinition($this->prefix('ui.manager'))->setClass('Generator\\UI\\CommandManager');
     // Add template factory
     $builder->addDefinition($this->prefix('latte.templateFactory'))->setClass('Generator\\Latte\\TemplateFactory')->setAutowired();
     // Add commands
     $builder->addDefinition($this->prefix('commands.info'))->setClass('Generator\\Commands\\InfoCommand')->setInject();
     $builder->addDefinition($this->prefix('commands.generate'))->setClass('Generator\\Commands\\GenerateCommand', [$builder->parameters['themes']])->setInject();
     $builder->addDefinition($this->prefix('commands.deploy'))->setClass('Generator\\Commands\\DeployCommand')->setInject();
     $builder->addDefinition($this->prefix('commands.error'))->setClass('Generator\\Commands\\ErrorCommand')->setInject();
 }
예제 #14
0
 /**
  * @throws ImageStorageException
  * @return array
  */
 public function getSettings()
 {
     if (!$this->settings) {
         $config = $this->validateConfig($this->defaults);
         $config['wwwDir'] = Nette\DI\Helpers::expand($config['wwwDir'], $this->getContainerBuilder()->parameters);
         // Validation
         $quality = $config['quality'];
         if (!is_int($quality) || !Validators::isInRange($quality, [0, 100])) {
             throw new ImageStorageException('Quality must be an integer from 0 to 100.');
         }
         foreach ($config['events'] as $name => &$array) {
             Validators::assert($array, 'array');
         }
         foreach ($config['helpers'] as $name => $class) {
             if (!class_exists($class) || $class instanceof IHelper) {
                 throw new ImageStorageException("Helper {$name} must be instance of " . IHelper::class);
             }
         }
         $this->settings = $config;
     }
     return $this->settings;
 }
 /**
  * @param $name
  * @return Nette\ComponentModel\IComponent
  * @throws Nette\UnexpectedValueException
  */
 public function createComponent($name)
 {
     $sl = $this->getServiceLocatorForFactories();
     $ucname = ucfirst($name);
     $method = 'createComponent' . $ucname;
     if ($ucname !== $name && method_exists($this, $method)) {
         $reflection = $this->getReflection()->getMethod($method);
         if ($reflection->getName() !== $method) {
             return;
         }
         $parameters = $reflection->parameters;
         $args = array();
         if (($first = reset($parameters)) && !$first->className) {
             $args[] = $name;
         }
         $args = Nette\DI\Helpers::autowireArguments($reflection, $args, $sl);
         $component = call_user_func_array(array($this, $method), $args);
         if (!$component instanceof Nette\ComponentModel\IComponent && !isset($this->components[$name])) {
             throw new Nette\UnexpectedValueException("Method {$reflection} did not return or create the desired component.");
         }
         return $component;
     }
 }
예제 #16
0
 /**
  * @param array $files
  * @throws InvalidStateException
  * @return array
  */
 protected function parsePosts($files)
 {
     $posts = [];
     $postsIds = [];
     $decoder = new NeonAdapter();
     foreach ($files as $file) {
         // Decode file
         $config = $decoder->load($file);
         // Merge
         $post = Config\Helpers::merge($config, $this->scheme);
         // Check unique post id
         if (in_array($post['id'], $postsIds)) {
             throw new InvalidStateException('Duplicate post.id "' . $post['id'] . '"');
         }
         // Expand post scheme
         $post = Helpers::expand($post, ['file' => dirname($file)], TRUE);
         // Unify
         $post['post'] = realpath($post['post']);
         $posts[] = $post;
         $postsIds[] = $post['id'];
     }
     return $posts;
 }
예제 #17
0
 private function updateDefinition($def)
 {
     $injects = array();
     $properties = DI\Helpers::getInjectProperties(new \ReflectionClass($def->getClass()), $this->getContainerBuilder());
     foreach ($properties as $property => $type) {
         $injects[] = new DI\Statement('$' . $property, array('@\\' . ltrim($type, '\\')));
     }
     foreach (get_class_methods($def->getClass()) as $method) {
         if (substr($method, 0, 6) === 'inject') {
             $injects[] = new DI\Statement($method);
         }
     }
     $setups = $def->getSetup();
     foreach ($injects as $inject) {
         foreach ($setups as $key => $setup) {
             if ($setup->getEntity() === $inject->getEntity()) {
                 $inject = $setup;
                 unset($setups[$key]);
             }
         }
         array_unshift($setups, $inject);
     }
     $def->setSetup($setups);
 }
예제 #18
0
파일: Compiler.php 프로젝트: DIPcom/Sandmin
 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, $namespace = NULL)
 {
     if (!empty($config['factories'])) {
         throw new Nette\DeprecatedException("Section 'factories' is deprecated, move definitions to section 'services' and append key 'autowired: no'.");
     }
     $services = isset($config['services']) ? $config['services'] : array();
     $depths = array();
     foreach ($services as $name => $def) {
         $path = array();
         while (Config\Helpers::isInheriting($def)) {
             $path[] = $def;
             $def = isset($services[$def[Config\Helpers::EXTENDS_KEY]]) ? $services[$def[Config\Helpers::EXTENDS_KEY]] : array();
             if (in_array($def, $path, TRUE)) {
                 throw new ServiceCreationException("Circular reference detected for service '{$name}'.");
             }
         }
         $depths[$name] = count($path);
     }
     array_multisort($depths, $services);
     foreach ($services as $origName => $def) {
         if ((string) (int) $origName === (string) $origName) {
             $postfix = $def instanceof Statement && is_string($def->getEntity()) ? '.' . $def->getEntity() : (is_scalar($def) ? ".{$def}" : '');
             $name = count($builder->getDefinitions()) + 1 . preg_replace('#\\W+#', '_', $postfix);
         } else {
             $name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
         }
         $params = $builder->parameters;
         if (is_array($def) && isset($def['parameters'])) {
             foreach ((array) $def['parameters'] as $k => $v) {
                 $v = explode(' ', is_int($k) ? $v : $k);
                 $params[end($v)] = $builder::literal('$' . end($v));
             }
         }
         $def = Helpers::expand($def, $params);
         if (($parent = Config\Helpers::takeParent($def)) && $parent !== $name) {
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : unserialize(serialize($builder->getDefinition($parent))));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::parseService($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
         if ($definition->getClass() === 'self' || $definition->getFactory() && $definition->getFactory()->getEntity() === 'self') {
             throw new Nette\DeprecatedException("Replace service definition '{$origName}: self' with '- {$origName}'.");
         }
     }
 }
예제 #19
0
 /**
  * @return string
  * @internal
  */
 public function generateContainer(DI\Compiler $compiler)
 {
     $loader = $this->createLoader();
     $compiler->addConfig(['parameters' => $this->parameters]);
     $fileInfo = [];
     foreach ($this->files as $info) {
         if (is_scalar($info[0])) {
             $fileInfo[] = "// source: {$info['0']} {$info['1']}";
             $info[0] = $loader->load($info[0], $info[1]);
         }
         $compiler->addConfig($this->fixCompatibility($info[0]));
     }
     $compiler->addDependencies($loader->getDependencies());
     $builder = $compiler->getContainerBuilder();
     $builder->addExcludedClasses($this->autowireExcludedClasses);
     foreach ($this->defaultExtensions as $name => $extension) {
         list($class, $args) = is_string($extension) ? [$extension, []] : $extension;
         if (class_exists($class)) {
             $args = DI\Helpers::expand($args, $this->parameters, TRUE);
             $compiler->addExtension($name, (new \ReflectionClass($class))->newInstanceArgs($args));
         }
     }
     $this->onCompile($this, $compiler);
     $classes = $compiler->compile();
     if (!empty($builder->parameters['container']['parent'])) {
         $classes[0]->setExtends($builder->parameters['container']['parent']);
     }
     return implode("\n", $fileInfo) . "\n\n" . implode("\n\n\n", $classes) . (($tmp = $builder->parameters['container']['class']) ? "\nclass {$tmp} extends {$builder->getClassName()} {}\n" : '');
 }
예제 #20
0
 /**
  * Creates a list of arguments using autowiring.
  * @return array
  * @internal
  */
 public function autowireArguments($class, $method, array $arguments)
 {
     $rc = new ReflectionClass($class);
     if (!$rc->hasMethod($method)) {
         if (!Nette\Utils\Arrays::isList($arguments)) {
             throw new ServiceCreationException("Unable to pass specified arguments to {$class}::{$method}().");
         }
         return $arguments;
     }
     $rm = $rc->getMethod($method);
     if (!$rm->isPublic()) {
         throw new ServiceCreationException("{$class}::{$method}() is not callable.");
     }
     $this->addDependency($rm);
     return Helpers::autowireArguments($rm, $arguments, $this);
 }
예제 #21
0
 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, $namespace = NULL)
 {
     $services = isset($config['services']) ? $config['services'] : array();
     $factories = isset($config['factories']) ? $config['factories'] : array();
     $all = array_merge($services, $factories);
     uasort($all, function ($a, $b) {
         return strcmp(Config\Helpers::isInheriting($a), Config\Helpers::isInheriting($b));
     });
     if (!empty($config['factories'])) {
         trigger_error("Section 'factories' is deprecated, move definitions to section 'services' and append key 'autowired: no'.", E_USER_DEPRECATED);
     }
     foreach ($all as $origName => $def) {
         if ((string) (int) $origName === (string) $origName) {
             $name = count($builder->getDefinitions()) . preg_replace('#\\W+#', '_', $def instanceof \stdClass ? ".{$def->value}" : (is_scalar($def) ? ".{$def}" : ''));
         } elseif (array_key_exists($origName, $services) && array_key_exists($origName, $factories)) {
             throw new ServiceCreationException("It is not allowed to use services and factories with the same name: '{$origName}'.");
         } else {
             $name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
         }
         $params = $builder->parameters;
         if (is_array($def) && isset($def['parameters'])) {
             foreach ((array) $def['parameters'] as $k => $v) {
                 $v = explode(' ', is_int($k) ? $v : $k);
                 $params[end($v)] = $builder::literal('$' . end($v));
             }
         }
         $def = Helpers::expand($def, $params);
         if (($parent = Config\Helpers::takeParent($def)) && $parent !== $name) {
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : unserialize(serialize($builder->getDefinition($parent))));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::parseService($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
         if (array_key_exists($origName, $factories)) {
             $definition->setAutowired(FALSE);
         }
         if ($definition->class === 'self') {
             $definition->class = $origName;
             trigger_error("Replace service definition '{$origName}: self' with '- {$origName}'.", E_USER_DEPRECATED);
         }
         if ($definition->factory && $definition->factory->entity === 'self') {
             $definition->factory->entity = $origName;
             trigger_error("Replace service definition '{$origName}: self' with '- {$origName}'.", E_USER_DEPRECATED);
         }
     }
 }
예제 #22
0
 public function getSettings()
 {
     $config = $this->validateConfig($this->defaults, $this->config);
     $config['wwwDir'] = Nette\DI\Helpers::expand($config['wwwDir'], $this->getContainerBuilder()->parameters);
     return $config;
 }
예제 #23
0
파일: Helper.php 프로젝트: venne/tester
 public function prepareTestEnvironment()
 {
     if (!is_dir(TEMP_DIR . '/environments')) {
         mkdir(TEMP_DIR . '/environments');
     }
     $target = TEMP_DIR . '/environments/' . $this->environmentCounter++;
     mkdir($target);
     copy(__DIR__ . '/env/sandbox.php', $target . '/sandbox.php');
     $c = (include $target . '/sandbox.php');
     foreach ($c as $path) {
         if (!file_exists($path)) {
             mkdir($path, 0777, true);
         }
     }
     copy(dirname(dirname(TEMP_DIR)) . '/config/config.neon', $c['configDir'] . '/config.neon');
     copy(dirname(dirname(TEMP_DIR)) . '/config/settings.php', $c['configDir'] . '/settings.php');
     copy(dirname(dirname(TEMP_DIR)) . '/temp/database.db', $c['tempDir'] . '/database.db');
     $configurator = $this->getConfigurator();
     $configurator->addParameters($c);
     $parameters = (include $c['configDir'] . '/settings.php');
     foreach ($parameters['modules'] as &$module) {
         $module['path'] = \Nette\DI\Helpers::expand($module['path'], $c + $this->getContainer()->parameters);
     }
     $configurator->addParameters($parameters);
     mkdir($c['tempDir'] . '/cache');
     if ($this->container) {
         $this->reloadContainer();
     }
 }
 /**
  * Creates a list of arguments using autowiring.
  *
  * @return array
  */
 public function autowireArguments($class, $method, array $arguments)
 {
     $rc = Nette\Reflection\ClassType::from($class);
     if (!$rc->hasMethod($method)) {
         if (!Nette\Utils\Validators::isList($arguments)) {
             throw new ServiceCreationException("Unable to pass specified arguments to {$class}::{$method}().");
         }
         return $arguments;
     }
     $rm = $rc->getMethod($method);
     if ($rm->isAbstract() || !$rm->isPublic()) {
         throw new ServiceCreationException("{$rm} is not callable.");
     }
     $this->addDependency($rm->getFileName());
     return Helpers::autowireArguments($rm, $arguments, $this);
 }
예제 #25
0
 /**
  * @param string $name
  * @param boolean $recursive
  * @return mixed
  */
 public function expand($name, $recursive = FALSE)
 {
     return Helpers::expand("%{$name}%", $this->parameters, $recursive);
 }
예제 #26
0
파일: Compiler.php 프로젝트: kukulich/di
 /**
  * Use Helpers::filterArguments()
  */
 public static function filterArguments(array $args) : array
 {
     return Helpers::filterArguments($args);
 }
예제 #27
0
 /**
  * Expands %placeholders%.
  * @param  mixed
  * @return mixed
  * @deprecated
  */
 public function expand($s)
 {
     return Helpers::expand($s, $this->parameters);
 }
예제 #28
0
 /**
  * @param null $parameters
  * @return array
  */
 protected function getDefaultParameters($parameters = NULL)
 {
     $parameters = (array) $parameters;
     $debugMode = isset($parameters['debugMode']) ? $parameters['debugMode'] : static::detectDebugMode();
     $ret = array('debugMode' => $debugMode, 'environment' => ($e = static::detectEnvironment()) ? $e : ($debugMode ? 'development' : 'production'), 'consoleMode' => PHP_SAPI === 'cli', 'container' => array('class' => 'SystemContainer', 'parent' => 'Nette\\DI\\Container'));
     $settings = (require $parameters['configDir'] . '/settings.php');
     foreach ($settings['modules'] as &$module) {
         $module['path'] = \Nette\DI\Helpers::expand($module['path'], $parameters);
     }
     $parameters = $settings + $parameters + $ret;
     $parameters['productionMode'] = !$parameters['debugMode'];
     return $parameters;
 }
예제 #29
0
 /**
  * Expands %placeholders% in strings.
  * @return mixed
  * @deprecated
  */
 public function expand($value)
 {
     return Helpers::expand($value, $this->parameters);
 }
 private function _getConfig()
 {
     $config = $this->validateConfig($this->defaults, $this->config);
     $config['data_path'] = Nette\DI\Helpers::expand($config['data_path'], $this->getContainerBuilder()->parameters);
     return $config;
 }