eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\Contextualizer::mapConfigArray PHP Метод

mapConfigArray() публичный Метод

public mapConfigArray ( $id, array $config, $options )
$config array
    public function mapConfigArray($id, array $config, $options = 0)
    {
        $this->mapReservedScopeArray($id, $config, ConfigResolver::SCOPE_DEFAULT);
        $this->mapReservedScopeArray($id, $config, ConfigResolver::SCOPE_GLOBAL);
        $defaultSettings = $this->getContainerParameter($this->namespace . '.' . ConfigResolver::SCOPE_DEFAULT . '.' . $id, array());
        $globalSettings = $this->getContainerParameter($this->namespace . '.' . ConfigResolver::SCOPE_GLOBAL . '.' . $id, array());
        foreach ($this->availableSiteAccesses as $scope) {
            // for a siteaccess, we have to merge the default value,
            // the group value(s), the siteaccess value and the global
            // value of the settings.
            $groupsSettings = array();
            if (isset($this->groupsBySiteAccess[$scope]) && is_array($this->groupsBySiteAccess[$scope])) {
                $groupsSettings = $this->groupsArraySetting($this->groupsBySiteAccess[$scope], $id, $config, $options & static::MERGE_FROM_SECOND_LEVEL);
            }
            $scopeSettings = array();
            if (isset($config[$this->siteAccessNodeName][$scope][$id])) {
                $scopeSettings = $config[$this->siteAccessNodeName][$scope][$id];
            }
            if ($options & static::MERGE_FROM_SECOND_LEVEL) {
                // array_merge() has to be used because we don't
                // know whether we have a hash or a plain array
                $keys1 = array_unique(array_merge(array_keys($defaultSettings), array_keys($groupsSettings), array_keys($scopeSettings), array_keys($globalSettings)));
                $mergedSettings = array();
                foreach ($keys1 as $key) {
                    // Only merge if actual setting is an array.
                    // We assume default setting to be a clear reference for this.
                    // If the setting is not an array, we copy the right value, in respect to the precedence:
                    // 1. global
                    // 2. SiteAccess
                    // 3. Group
                    // 4. default
                    if (array_key_exists($key, $defaultSettings) && !is_array($defaultSettings[$key])) {
                        if (array_key_exists($key, $globalSettings)) {
                            $mergedSettings[$key] = $globalSettings[$key];
                        } elseif (array_key_exists($key, $scopeSettings)) {
                            $mergedSettings[$key] = $scopeSettings[$key];
                        } elseif (array_key_exists($key, $groupsSettings)) {
                            $mergedSettings[$key] = $groupsSettings[$key];
                        } else {
                            $mergedSettings[$key] = $defaultSettings[$key];
                        }
                    } else {
                        $mergedSettings[$key] = array_merge(isset($defaultSettings[$key]) ? $defaultSettings[$key] : array(), isset($groupsSettings[$key]) ? $groupsSettings[$key] : array(), isset($scopeSettings[$key]) ? $scopeSettings[$key] : array(), isset($globalSettings[$key]) ? $globalSettings[$key] : array());
                    }
                }
            } else {
                $mergedSettings = array_merge($defaultSettings, $groupsSettings, $scopeSettings, $globalSettings);
            }
            if ($options & static::UNIQUE) {
                $mergedSettings = array_values(array_unique($mergedSettings));
            }
            $this->container->setParameter("{$this->namespace}.{$scope}.{$id}", $mergedSettings);
        }
    }

Usage Example

 /**
  * Test that settings array a properly merged when defined in several
  * scopes.
  *
  * @dataProvider fullMapConfigArrayProvider
  */
 public function testFullMapConfigArray($testId, $siteaccess, array $groups, array $defaultValue, array $globalValue, array $config, $options, array $expected, $customSANodeKey = null)
 {
     $this->contextualizer->setAvailableSiteAccesses($config['siteaccess']['list']);
     $this->contextualizer->setGroupsBySiteAccess(array($siteaccess => $groups));
     $hasParameterMap = array(array($this->namespace . '.' . ConfigResolver::SCOPE_DEFAULT . '.' . $testId, true), array($this->namespace . '.' . ConfigResolver::SCOPE_GLOBAL . '.' . $testId, true));
     $getParameterMap = array(array($this->namespace . '.' . ConfigResolver::SCOPE_DEFAULT . '.' . $testId, $defaultValue), array($this->namespace . '.' . ConfigResolver::SCOPE_GLOBAL . '.' . $testId, $globalValue));
     $this->container->expects($this->any())->method('hasParameter')->will($this->returnValueMap($hasParameterMap));
     $this->container->expects($this->any())->method('getParameter')->will($this->returnValueMap($getParameterMap));
     $this->container->expects($this->any())->method('setParameter')->with($this->equalTo("{$this->namespace}.{$siteaccess}.{$testId}"), $this->equalTo($expected));
     if ($customSANodeKey !== null) {
         $this->contextualizer->setSiteAccessNodeName($customSANodeKey);
     }
     $this->contextualizer->mapConfigArray($testId, $config, $options);
 }