merge() public static method

Merges configurations. Left has higher priority than right one.
public static merge ( $left, $right ) : array | string
return array | string
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults + $this->elasticaDefaults);
     if (empty($config['connections'])) {
         $config['connections']['default'] = Config\Helpers::merge(array_intersect_key($config, $this->connectionDefaults), $builder->expand($this->connectionDefaults));
     } else {
         foreach ($config['connections'] as $name => $connectionConfig) {
             $config['connections'][$name] = Config\Helpers::merge($connectionConfig, $builder->expand($this->connectionDefaults));
         }
     }
     // replace curl string options with their CURLOPT_ constant values
     foreach ($config['connections'] as $name => $connectionConfig) {
         $curlOptions = array();
         foreach ($connectionConfig['config']['curl'] as $option => $value) {
             if (!defined($constant = 'CURLOPT_' . strtoupper($option))) {
                 throw new Nette\InvalidArgumentException('There is no constant "' . $constant . '", therefore "' . $option . '" cannot be set.');
             }
             $curlOptions[constant($constant)] = $value;
         }
         $config['connections'][$name]['config']['curl'] = $curlOptions;
     }
     $elasticaConfig = array_intersect_key($config, $this->elasticaDefaults);
     $elastica = $builder->addDefinition($this->prefix('elastica'))->setClass('Kdyby\\ElasticSearch\\Client', array($elasticaConfig));
     if ($config['debugger']) {
         $builder->addDefinition($this->prefix('panel'))->setClass('Kdyby\\ElasticSearch\\Diagnostics\\Panel');
         $elastica->addSetup($this->prefix('@panel') . '::register', array('@self'));
     }
 }
Esempio n. 2
0
 /**
  * @param array $resources
  * @param bool $minify
  * @param string $baseDir
  * @throws AssetsException
  * @return array
  */
 public function getAssets(array $resources, $minify, $baseDir)
 {
     $config = [];
     $return = [];
     foreach ($resources as $resource) {
         $contents = file_get_contents($resource);
         $decompiled = Strings::endsWith($resource, '.json') ? json_decode($contents, TRUE) : Neon::decode($contents);
         $config = \Nette\DI\Config\Helpers::merge($config, $decompiled);
     }
     foreach ($config as $moduleArray) {
         foreach ($moduleArray as $type => $typeArray) {
             if (!isset(self::$supportTypes[$type])) {
                 throw new AssetsException("Found section '{$type}', but expected one of " . implode(', ', array_keys(self::$supportTypes)));
             }
             foreach ($typeArray as $minified => $assets) {
                 if ($minify) {
                     $return[$type][$minified] = TRUE;
                     continue;
                 }
                 foreach ((array) $assets as $row) {
                     if (strpos($row, '*') !== FALSE) {
                         /** @var \SplFileInfo $file */
                         foreach (Finder::findFiles(basename($row))->in($baseDir . '/' . dirname($row)) as $file) {
                             $return[$type][$minified][] = dirname($row) . '/' . $file->getBasename();
                         }
                     } else {
                         $return[$type][$minified][] = $row;
                     }
                 }
             }
         }
     }
     return $return;
 }
 /**
  * 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]);
     }
 }
Esempio n. 4
0
 /**
  * @param string $name
  * @param array $config
  * @return Nette\DI\ServiceDefinition
  */
 protected function buildClient($name, $config)
 {
     $builder = $this->getContainerBuilder();
     $defaultConfig = $this->getConfig($this->clientDefaults);
     if ($parentName = Config\Helpers::takeParent($config)) {
         Nette\Utils\Validators::assertField($this->configuredClients, $parentName, 'array', "parent configuration '%', are you sure it's defined?");
         $defaultConfig = Config\Helpers::merge($this->configuredClients[$parentName], $defaultConfig);
     }
     $config = Config\Helpers::merge($config, $defaultConfig);
     $config = array_intersect_key(self::fixClientConfig($config), $this->clientDefaults);
     $client = $builder->addDefinition($clientName = $this->prefix(($name ? $name . '_' : '') . 'client'))->setClass('Kdyby\\Redis\\RedisClient', array('host' => $config['host'], 'port' => $config['port'], 'database' => $config['database'], 'timeout' => $config['timeout'], 'auth' => $config['auth'], 'persistent' => $config['persistent']));
     if (empty($builder->parameters[$this->name]['defaultClient'])) {
         $builder->parameters[$this->name]['defaultClient'] = $clientName;
         $this->configuredClients['default'] = $config;
         $builder->addDefinition($this->prefix('default_client'))->setClass('Kdyby\\Redis\\RedisClient')->setFactory('@' . $clientName)->setAutowired(FALSE);
     } else {
         $client->setAutowired(FALSE);
     }
     $this->configuredClients[$name] = $config;
     $client->addSetup('setupLockDuration', array($config['lockDuration'], $config['lockAcquireTimeout']));
     $client->addSetup('setConnectionAttempts', array($config['connectionAttempts']));
     $client->addTag('redis.client');
     if (array_key_exists('debugger', $config) && $config['debugger']) {
         $builder->addDefinition($panelName = $clientName . '.panel')->setClass('Kdyby\\Redis\\Diagnostics\\Panel')->setFactory('Kdyby\\Redis\\Diagnostics\\Panel::register')->addSetup('$renderPanel', array($config['debugger'] !== self::PANEL_COUNT_MODE))->addSetup('$name', array($name ?: 'default'));
         $client->addSetup('setPanel', array('@' . $panelName));
     }
     return $client;
 }
Esempio n. 5
0
 /**
  * Returns extension configuration.
  * @param  array default unexpanded values.
  * @return array
  */
 public function getConfig(array $defaults = NULL)
 {
     $config = $this->compiler->getConfig();
     $config = isset($config[$this->name]) ? $config[$this->name] : array();
     unset($config['services'], $config['factories']);
     return Config\Helpers::merge($config, $this->compiler->getContainerBuilder()->expand($defaults));
 }
 /**
  * @param string $path
  * @param string $find
  * @param int $depth
  */
 public function addAutoloadConfig($path, $find = 'config.neon', $depth = -1)
 {
     // Development
     if (!$this->cacheConfig && $this->isDevelopment()) {
         foreach (Finder::find($find)->from($path)->limitDepth($depth) as $file) {
             $this->addConfig((string) $file);
         }
         return;
     }
     // Production
     $directory = $this->parameters['tempDir'] . '/cache/configs';
     $cachePath = $directory . '/' . Strings::webalize(str_replace(dirname($this->parameters['appDir']), '', $path)) . '.neon';
     if (file_exists($cachePath)) {
         $this->addConfig($cachePath);
         return;
     }
     $encoder = new Encoder();
     $decoder = new Decoder();
     @mkdir($directory);
     $content = [];
     foreach (Finder::find($find)->from($path)->limitDepth($depth) as $file) {
         $content = Helpers::merge($content, $decoder->decode(file_get_contents($file)));
     }
     file_put_contents($cachePath, $encoder->encode($content));
     $this->addConfig($cachePath);
 }
Esempio n. 7
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig();
     if (isset($config['server']) || isset($config['certificate'])) {
         $config = array('default' => $config);
     }
     if (empty($config)) {
         throw new \Exception('Please configure the APNs extensions.');
     }
     foreach ($config as $name => $conf) {
         if (!is_array($conf) || empty($conf['certificate'])) {
             throw new \Exception('Please configure the APNs extensions.');
         }
         $conf = Nette\DI\Config\Helpers::merge($conf, $this->defaults);
         if ($conf['environment'] == 1 || $conf['environment'] === 'production') {
             $conf['environment'] = 1;
         } else {
             $conf['environment'] = 0;
         }
         $this->processProvider($name, $conf);
         $this->processFeedback($name, $conf);
     }
     $builder->addDefinition($this->prefix('registry'))->setClass('Nemec\\Apns\\Registry', array($this->configuredProviders, $this->configuredFeedbacks, $builder->parameters[$this->name]['defaultProvider'], $builder->parameters[$this->name]['defaultFeedback']));
 }
 protected function loadNativeSessionHandler(array $session)
 {
     $builder = $this->getContainerBuilder();
     $params = array_intersect_key($session, array_flip(array('weight', 'timeout', 'database', 'prefix', 'auth', 'persistent')));
     if (substr($session['host'], 0, 1) === '/') {
         $savePath = $session['host'];
     } else {
         $savePath = sprintf('tcp://%s:%d', $session['host'], $session['port']);
     }
     if (!$params['persistent']) {
         unset($params['persistent']);
     }
     if (!$params['auth']) {
         unset($params['auth']);
     }
     $options = array('saveHandler' => 'redis', 'savePath' => $savePath . ($params ? '?' . http_build_query($params, '', '&') : ''));
     foreach ($builder->getDefinition('session')->setup as $statement) {
         if ($statement->entity === 'setOptions') {
             $statement->arguments[0] = Nette\DI\Config\Helpers::merge($options, $statement->arguments[0]);
             unset($options);
             break;
         }
     }
     if (isset($options)) {
         $builder->getDefinition('session')->addSetup('setOptions', array($options));
     }
 }
Esempio n. 9
0
	/**
	 * Reads configuration from INI file.
	 * @param  string  file name
	 * @return array
	 * @throws Nette\InvalidStateException
	 */
	public function load($file)
	{
		$ini = @parse_ini_file($file, TRUE); // intentionally @
		if ($ini === FALSE) {
			$error = error_get_last();
			throw new Nette\InvalidStateException("parse_ini_file(): $error[message]");
		}

		$data = array();
		foreach ($ini as $secName => $secData) {
			if (is_array($secData)) { // is section?
				if (substr($secName, -1) === self::RAW_SECTION) {
					$secName = substr($secName, 0, -1);
				} else { // process key nesting separator (key1.key2.key3)
					$tmp = array();
					foreach ($secData as $key => $val) {
						$cursor = & $tmp;
						$key = str_replace(self::ESCAPED_KEY_SEPARATOR, "\xFF", $key);
						foreach (explode(self::KEY_SEPARATOR, $key) as $part) {
							$part = str_replace("\xFF", self::KEY_SEPARATOR, $part);
							if (!isset($cursor[$part]) || is_array($cursor[$part])) {
								$cursor = & $cursor[$part];
							} else {
								throw new Nette\InvalidStateException("Invalid key '$key' in section [$secName] in file '$file'.");
							}
						}
						$cursor = $val;
					}
					$secData = $tmp;
				}

				$parts = explode(self::INHERITING_SEPARATOR, $secName);
				if (count($parts) > 1) {
					$secName = trim($parts[0]);
					$secData[Helpers::EXTENDS_KEY] = trim($parts[1]);
				}
			}

			$cursor = & $data; // nesting separator in section name
			foreach (explode(self::KEY_SEPARATOR, $secName) as $part) {
				if (!isset($cursor[$part]) || is_array($cursor[$part])) {
					$cursor = & $cursor[$part];
				} else {
					throw new Nette\InvalidStateException("Invalid section [$secName] in file '$file'.");
				}
			}

			if (is_array($secData) && is_array($cursor)) {
				$secData = Helpers::merge($secData, $cursor);
			}

			$cursor = $secData;
		}

		return $data;
	}
Esempio n. 10
0
 /**
  * @return array
  */
 protected function generateConfig()
 {
     $config = array();
     $loader = $this->createLoader();
     foreach ($this->configFiles as $info) {
         $config = Config\Helpers::merge($loader->load($info[0], $info[1]), $config);
     }
     $this->dependencies = array_merge($this->dependencies, $loader->getDependencies());
     return Config\Helpers::merge($config, $this->config);
 }
 /**
  * @return array
  * @throws \Librette\Application\PresenterFactory\InvalidStateException
  */
 protected function getMappingConfig()
 {
     $globalConfig = $this->compiler->getConfig();
     if (isset($globalConfig['nette']['application']['mapping']) && isset($globalConfig[$this->name]['mapping'])) {
         throw new InvalidStateException("You cannot use both nette.application.mapping and {$this->name}.mapping config section, choose one.");
     }
     $userConfig = isset($globalConfig[$this->name]['mapping']) ? $globalConfig[$this->name]['mapping'] : (isset($globalConfig['nette']['application']['mapping']) ? $globalConfig['nette']['application']['mapping'] : []);
     $config = Nette\DI\Config\Helpers::merge($userConfig, $this->defaults['mapping']);
     return $config;
 }
 /**
  * @return array
  */
 public function getConfig(array $defaults = NULL, $expand = TRUE)
 {
     $config = parent::getConfig($defaults, $expand);
     // ignoredAnnotations
     $globalConfig = $this->compiler->getConfig();
     if (!empty($globalConfig['doctrine']['ignoredAnnotations'])) {
         trigger_error("Section 'doctrine: ignoredAnnotations:' is deprecated, please use '{$this->name}: ignore:' ", E_USER_DEPRECATED);
         $config = Nette\DI\Config\Helpers::merge($config, array('ignore' => $globalConfig['doctrine']['ignoredAnnotations']));
     }
     return $this->compiler->getContainerBuilder()->expand($config);
 }
Esempio n. 13
0
 /**
  * @param array $data
  * @param string $includeKeyword
  * @return array
  */
 private function mergeIncludedFiles($data, $filename, $includeKeyword)
 {
     if (isset($data[$includeKeyword])) {
         foreach ($data[$includeKeyword] as $include) {
             $includeFile = dirname($filename) . DIRECTORY_SEPARATOR . $include;
             $includeData = $this->parse($includeFile);
             $data = Helpers::merge($includeData, $data);
         }
         unset($data[$includeKeyword]);
     }
     return $data;
 }
Esempio n. 14
0
 /**
  * Checks whether $config contains only $expected items and returns combined array.
  * @return array
  * @throws Nette\InvalidStateException
  */
 public function validateConfig(array $expected, array $config = NULL, $name = NULL)
 {
     if (func_num_args() === 1) {
         return $this->config = $this->validateConfig($expected, $this->config);
     }
     if ($extra = array_diff_key((array) $config, $expected)) {
         $name = $name ?: $this->name;
         $extra = implode(", {$name}.", array_keys($extra));
         throw new Nette\InvalidStateException("Unknown configuration option {$name}.{$extra}.");
     }
     return Config\Helpers::merge($config, $expected);
 }
Esempio n. 15
0
 /**
  * Checks whether $config contains only $expected items and returns combined array.
  * @return array
  * @throws Nette\InvalidStateException
  */
 public function validateConfig(array $expected, array $config = NULL, $name = NULL)
 {
     if (func_num_args() === 1) {
         return $this->config = $this->validateConfig($expected, $this->config);
     }
     if ($extra = array_diff_key((array) $config, $expected)) {
         $name = $name ?: $this->name;
         $hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($expected), key($extra));
         $extra = $hint ? key($extra) : implode(", {$name}.", array_keys($extra));
         throw new Nette\InvalidStateException("Unknown configuration option {$name}.{$extra}" . ($hint ? ", did you mean {$name}.{$hint}?" : '.'));
     }
     return Config\Helpers::merge($config, $expected);
 }
Esempio n. 16
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->getDefaultConfig());
     $builder->addDefinition($this->prefix('cssNamingConvention'))->setFactory('WebLoader\\DefaultOutputNamingConvention::createCssConvention');
     $builder->addDefinition($this->prefix('jsNamingConvention'))->setFactory('WebLoader\\DefaultOutputNamingConvention::createJsConvention');
     $builder->parameters['webloader'] = $config;
     $loaderFactoryTempPaths = array();
     foreach (array('css', 'js') as $type) {
         foreach ($config[$type] as $name => $wlConfig) {
             $wlConfig = Helpers::merge($wlConfig, $config[$type . 'Defaults']);
             $this->addWebLoader($builder, $type . ucfirst($name), $wlConfig);
             $loaderFactoryTempPaths[strtolower($name)] = $wlConfig['tempPath'];
         }
     }
     $builder->addDefinition($this->prefix('factory'))->setClass('WebLoader\\Nette\\LoaderFactory', array($loaderFactoryTempPaths));
 }
Esempio n. 17
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults + $this->elasticaDefaults);
     if (empty($config['connections'])) {
         $config['connections']['default'] = Config\Helpers::merge(array_intersect_key($config, $this->connectionDefaults), $builder->expand($this->connectionDefaults));
     } else {
         foreach ($config['connection'] as $name => $connectionConfig) {
             $config['connections'][$name] = Config\Helpers::merge($connectionConfig, $builder->expand($this->connectionDefaults));
         }
     }
     $elasticaConfig = array_intersect_key($config, $this->elasticaDefaults);
     $elastica = $builder->addDefinition($this->prefix('elastica'))->setClass('Kdyby\\ElasticSearch\\Client', array($elasticaConfig));
     if ($config['debugger']) {
         $builder->addDefinition($this->prefix('panel'))->setClass('Kdyby\\ElasticSearch\\Diagnostics\\Panel');
         $elastica->addSetup($this->prefix('@panel') . '::register', array('@self'));
     }
 }
Esempio n. 18
0
 public function loadConfiguration()
 {
     $this->listeners = [];
     $this->allowedManagerSetup = [];
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     $userConfig = $this->getConfig();
     if (!array_key_exists('debugger', $userConfig)) {
         if (in_array(php_sapi_name(), ['cli', 'phpdbg'], TRUE)) {
             $config['debugger'] = FALSE;
             // disable by default in CLI
         } elseif (!$config['debugger']) {
             $config['debugger'] = self::PANEL_COUNT_MODE;
         }
     }
     $evm = $builder->addDefinition($this->prefix('manager'))->setClass('Kdyby\\Events\\EventManager');
     if ($config['debugger']) {
         $defaults = ['dispatchTree' => FALSE, 'dispatchLog' => TRUE, 'events' => TRUE, 'listeners' => FALSE];
         if (is_array($config['debugger'])) {
             $config['debugger'] = Nette\DI\Config\Helpers::merge($config['debugger'], $defaults);
         } else {
             $config['debugger'] = $config['debugger'] !== self::PANEL_COUNT_MODE;
         }
         $evm->addSetup('Kdyby\\Events\\Diagnostics\\Panel::register(?, ?)->renderPanel = ?', ['@self', '@container', $config['debugger']]);
     }
     if ($config['exceptionHandler'] !== NULL) {
         $evm->addSetup('setExceptionHandler', $this->filterArgs($config['exceptionHandler']));
     }
     Nette\Utils\Validators::assertField($config, 'subscribers', 'array');
     foreach ($config['subscribers'] as $i => $subscriber) {
         $def = $builder->addDefinition($this->prefix('subscriber.' . $i));
         $def->setFactory(Nette\DI\Compiler::filterArguments([is_string($subscriber) ? new Nette\DI\Statement($subscriber) : $subscriber])[0]);
         list($subscriberClass) = (array) $builder->normalizeEntity($def->getEntity());
         if (class_exists($subscriberClass)) {
             $def->setClass($subscriberClass);
         }
         $def->setAutowired(FALSE);
         $def->addTag(self::SUBSCRIBER_TAG);
     }
     if (class_exists('Symfony\\Component\\EventDispatcher\\Event')) {
         $builder->addDefinition($this->prefix('symfonyProxy'))->setClass('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->setFactory('Kdyby\\Events\\SymfonyDispatcher');
     }
     $this->loadedConfig = $config;
 }
Esempio n. 19
0
 public function loadConfiguration()
 {
     $container = $this->getContainerBuilder();
     $config = $this->compiler->getConfig();
     $prefix = isset($config[$this->name]) ? $this->name : 'nette';
     if ($oldSection = !isset($config[$this->name]) && isset($config['nette']['mailer'])) {
         $config = Nette\DI\Config\Helpers::merge($config['nette']['mailer'], $this->defaults);
         //trigger_error("Configuration section 'nette.mailer' is deprecated, use section '$this->name' and service '$this->name.mailer' instead.", E_USER_DEPRECATED);
     } else {
         $config = $this->getConfig($this->defaults);
     }
     $this->validateConfig($this->defaults, $config, $oldSection ? 'nette.mailer' : $this->name);
     $mailer = $container->addDefinition($prefix . '.mailer')->setClass('Nette\\Mail\\IMailer');
     if (empty($config['smtp'])) {
         $mailer->setFactory('Nette\\Mail\\SendmailMailer');
     } else {
         $mailer->setFactory('Nette\\Mail\\SmtpMailer', array($config));
     }
 }
Esempio n. 20
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig();
     if (isset($config['apiKey'])) {
         $config = array('default' => $config);
     }
     if (empty($config)) {
         throw new \Exception('Please configure the GCM extensions.');
     }
     foreach ($config as $name => $conf) {
         if (!is_array($conf) || empty($conf['apiKey'])) {
             throw new \Exception('Please configure the GCM extensions.');
         }
         $conf = Nette\DI\Config\Helpers::merge($conf, $this->defaults);
         $this->processProvider($name, $conf);
     }
     $builder->addDefinition($this->prefix('registry'))->setClass('Nemec\\Gcm\\Registry', array($this->configuredProviders, $builder->parameters[$this->name]['defaultProvider']));
 }
 public function loadConfiguration()
 {
     parent::loadConfiguration();
     $config = $this->validateConfig($this->defaults);
     $containerBuilder = $this->getContainerBuilder();
     Validators::assertField($config, 'containerControls', 'array');
     $autowired = count($config['containerControls']) === 1;
     foreach ($config['containerControls'] as $key => $containerControlOptions) {
         if (is_string($containerControlOptions)) {
             $containerControlOptions = ['name' => $containerControlOptions];
         } else {
             $containerControlOptions['name'] = $key;
         }
         $containerControlOptions = ConfigHelpers::merge($containerControlOptions, $this->containerControlDefaults);
         Validators::assertField($containerControlOptions, 'name', 'string');
         Validators::assertField($containerControlOptions, 'implement', 'string');
         $containerBuilder->addDefinition($this->prefix($containerControlOptions['name'] . 'ContainerControlFactory'))->setImplement($containerControlOptions['implement'])->setAutowired($autowired);
     }
 }
Esempio n. 22
0
 /**
  * @param array $items
  * @return array
  */
 public function parseItems(array $items)
 {
     $builder = $this->getContainerBuilder();
     $defaults = $this->itemDefaults;
     $_this = $this;
     array_walk($items, function (&$item, $name) use($builder, $defaults, $_this) {
         if (is_string($item)) {
             $item = array('title' => null, 'target' => $item);
         }
         $item['name'] = $name;
         $item = Helpers::merge($item, $builder->expand($defaults));
         if ($item['title'] === null) {
             $item['name'] = null;
             $item['title'] = $name;
         }
         if (count($item['items']) > 0) {
             $item['items'] = $_this->parseItems($item['items']);
         }
     });
     return $items;
 }
Esempio n. 23
0
 /**
  * @throws InvalidConfigException
  */
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig();
     if (!array_key_exists('tokenStorage', $config)) {
         $tokenStorageDefinition = $builder->addDefinition($this->prefix('tokenFactory'))->setClass(MemoryTokenStorage::class);
     } else {
         // touch reference to validate it
         if (!$builder->getServiceName($tokenStorageDefinition = $config['tokenStorage'])) {
             throw new InvalidConfigException("Invalid reference to service implementing ITokenStorage given: {$config['tokenStorage']}");
         }
     }
     if (array_key_exists('clients', $config) && is_array($config['clients'])) {
         $clients = [];
         foreach ($config['clients'] as $name => $clientConfig) {
             $clients[$name] = $this->configureClient(Helpers::merge($clientConfig, $builder->expand($this->defaults)), $tokenStorageDefinition, $name);
         }
         $this->configureClientsPool($clients);
     } else {
         $this->configureClient(Helpers::merge($config, $builder->expand($this->defaults)), $tokenStorageDefinition);
     }
 }
Esempio n. 24
0
 public function loadConfiguration()
 {
     $this->listeners = array();
     $this->allowedManagerSetup = array();
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     $userConfig = $this->getConfig();
     if (!isset($userConfig['debugger']) && !$config['debugger']) {
         $config['debugger'] = self::PANEL_COUNT_MODE;
     }
     $evm = $builder->addDefinition($this->prefix('manager'))->setClass('Kdyby\\Events\\EventManager')->setInject(FALSE);
     if ($config['debugger']) {
         $defaults = array('dispatchTree' => FALSE, 'dispatchLog' => TRUE, 'events' => TRUE, 'listeners' => FALSE);
         if (is_array($config['debugger'])) {
             $config['debugger'] = Nette\DI\Config\Helpers::merge($config['debugger'], $defaults);
         } else {
             $config['debugger'] = $config['debugger'] !== self::PANEL_COUNT_MODE;
         }
         $evm->addSetup('Kdyby\\Events\\Diagnostics\\Panel::register(?, ?)->renderPanel = ?', array('@self', '@container', $config['debugger']));
     }
     if ($config['exceptionHandler'] !== NULL) {
         $evm->addSetup('setExceptionHandler', $this->filterArgs($config['exceptionHandler']));
     }
     Nette\Utils\Validators::assertField($config, 'subscribers', 'array');
     foreach ($config['subscribers'] as $subscriber) {
         $def = $builder->addDefinition($this->prefix('subscriber.' . md5(Nette\Utils\Json::encode($subscriber))));
         list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($subscriber) ? new Nette\DI\Statement($subscriber) : $subscriber));
         list($subscriberClass) = (array) $builder->normalizeEntity($def->factory->entity);
         if (class_exists($subscriberClass)) {
             $def->class = $subscriberClass;
         }
         $def->setAutowired(FALSE);
         $def->addTag(self::SUBSCRIBER_TAG);
     }
     if (class_exists('Symfony\\Component\\EventDispatcher\\Event')) {
         $builder->addDefinition($this->prefix('symfonyProxy'))->setClass('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->setFactory('Kdyby\\Events\\SymfonyDispatcher');
     }
 }
Esempio n. 25
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;
 }
Esempio n. 26
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->getDefaultConfig());
     $builder->addDefinition($this->prefix('cssNamingConvention'))->setFactory('WebLoader\\DefaultOutputNamingConvention::createCssConvention');
     $builder->addDefinition($this->prefix('jsNamingConvention'))->setFactory('WebLoader\\DefaultOutputNamingConvention::createJsConvention');
     if ($config['debugger']) {
         $builder->addDefinition($this->prefix('tracyPanel'))->setClass('WebLoader\\Nette\\Diagnostics\\Panel')->setArguments(array($builder->expand('%appDir%')));
     }
     $builder->parameters['webloader'] = $config;
     $loaderFactoryTempPaths = array();
     foreach (array('css', 'js') as $type) {
         foreach ($config[$type] as $name => $wlConfig) {
             $wlConfig = Helpers::merge($wlConfig, $config[$type . 'Defaults']);
             $this->addWebLoader($builder, $type . ucfirst($name), $wlConfig);
             $loaderFactoryTempPaths[strtolower($name)] = $wlConfig['tempPath'];
             if (!is_dir($wlConfig['tempDir']) || !is_writable($wlConfig['tempDir'])) {
                 throw new CompilationException(sprintf("You must create a writable directory '%s'", $wlConfig['tempDir']));
             }
         }
     }
     $builder->addDefinition($this->prefix('factory'))->setClass('WebLoader\\Nette\\LoaderFactory', array($loaderFactoryTempPaths, $this->name));
 }
Esempio n. 27
0
 private function getSection(array $data, $key, $file)
 {
     Validators::assertField($data, $key, 'array|null', "section '%' in file '{$file}'");
     $item = $data[$key];
     if ($parent = Helpers::takeParent($item)) {
         $item = Helpers::merge($item, $this->getSection($data, $parent, $file));
     }
     return $item;
 }
Esempio n. 28
0
 /**
  * Adds new parameters. The %params% will be expanded.
  * @return self
  */
 public function addParameters(array $params)
 {
     $this->parameters = DI\Config\Helpers::merge($params, $this->parameters);
     return $this;
 }
Esempio n. 29
0
 /**
  * Adds new configuration.
  * @return self
  */
 public function addConfig(array $config) : self
 {
     $this->config = Config\Helpers::merge($config, $this->config);
     return $this;
 }
Esempio n. 30
0
 /**
  * @param IParametersProvider $extension
  * @throws AssertionException
  */
 private function setupParameters(IParametersProvider $extension)
 {
     $config = new ParametersConfig();
     $extension->setupParameters($config);
     $parameters = $config->getParameters();
     Validators::assert($parameters, 'array');
     $builder = $this->getContainerBuilder();
     if (count($parameters) > 0) {
         $builder->parameters = \Nette\DI\Config\Helpers::merge($builder->expand($parameters), $builder->parameters);
     }
 }