本文整理汇总了PHP中Nette\DI\Config\Helpers::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Helpers::merge方法的具体用法?PHP Helpers::merge怎么用?PHP Helpers::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\Config\Helpers
的用法示例。
在下文中一共展示了Helpers::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadConfiguration
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'));
}
}
示例2: getAssets
/**
* @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;
}
示例3: loadConfiguration
/**
* 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]);
}
}
示例4: buildClient
/**
* @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;
}
示例5: getConfig
/**
* 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));
}
示例6: addAutoloadConfig
/**
* @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);
}
示例7: loadConfiguration
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']));
}
示例8: loadNativeSessionHandler
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));
}
}
示例9: load
/**
* 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;
}
示例10: generateConfig
/**
* @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);
}
示例11: getMappingConfig
/**
* @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;
}
示例12: getConfig
/**
* @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);
}
示例13: mergeIncludedFiles
/**
* @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;
}
示例14: validateConfig
/**
* 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);
}
示例15: validateConfig
/**
* 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);
}