Nette\DI\Config\Helpers::merge PHP Method

merge() public static method

Merges configurations. Left has higher priority than right one.
public static merge ( $left, $right ) : array | string
return array | string
    public static function merge($left, $right)
    {
        if (is_array($left) && is_array($right)) {
            foreach ($left as $key => $val) {
                if (is_int($key)) {
                    $right[] = $val;
                } else {
                    if (is_array($val) && isset($val[self::EXTENDS_KEY])) {
                        if ($val[self::EXTENDS_KEY] === self::OVERWRITE) {
                            unset($val[self::EXTENDS_KEY]);
                        }
                    } elseif (isset($right[$key])) {
                        $val = static::merge($val, $right[$key]);
                    }
                    $right[$key] = $val;
                }
            }
            return $right;
        } elseif ($left === NULL && is_array($right)) {
            return $right;
        } else {
            return $left;
        }
    }

Usage Example

コード例 #1
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['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'));
     }
 }
All Usage Examples Of Nette\DI\Config\Helpers::merge