public function preMap(array $config, ContextualizerInterface $contextualizer) { $scopes = array_merge([ConfigResolver::SCOPE_DEFAULT, ConfigResolver::SCOPE_GLOBAL], $config['siteaccess']['list'], array_keys($config['siteaccess']['groups'])); foreach ($scopes as $scope) { if (!isset($config[$contextualizer->getSiteAccessNodeName()][$scope][static::NODE_KEY])) { continue; } $locationViewConfig =& $config[$contextualizer->getSiteAccessNodeName()][$scope][static::NODE_KEY]; $contentViewConfig =& $config[$contextualizer->getSiteAccessNodeName()][$scope][ContentView::NODE_KEY]; // view rules without a custom controller are moved from $locationViewConfig to $contentViewConfig foreach ($locationViewConfig as $viewIdentifier => $viewRules) { foreach ($viewRules as $viewRuleIdentifier => $viewRule) { if (!isset($viewRule['controller'])) { $contentViewConfig[$viewIdentifier][$viewRuleIdentifier] = $locationViewConfig[$viewIdentifier][$viewRuleIdentifier]; unset($locationViewConfig[$viewIdentifier][$viewRuleIdentifier]); } } if (count($locationViewConfig[$viewIdentifier]) === 0) { unset($locationViewConfig[$viewIdentifier]); } } } parent::preMap($config, $contextualizer); $contextualizer->mapConfigArray(ContentView::NODE_KEY, $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL); }
public function preMap(array $config, ContextualizerInterface $contextualizer) { foreach ($config['siteaccess']['groups'] as $group => $saArray) { if (isset($config['system'][$group][static::NODE_KEY])) { $contextualizer->setContextualParameter(static::NODE_KEY, $group, $config[$contextualizer->getSiteAccessNodeName()][$group][static::NODE_KEY]); } } $contextualizer->mapConfigArray(static::NODE_KEY, $config); }
/** * Triggers mapping process between semantic and internal configuration. * * @param array $config Parsed semantic configuration * @param ConfigurationMapperInterface|callable $mapper Mapper to use. Can be either an instance of ConfigurationMapper or a callable. * HookableConfigurationMapper can also be used. In this case, preMap() * and postMap() will be also called respectively before and after the mapping loop. * * If $mapper is a callable, the same arguments as defined in the signature * defined in ConfigurationMapper interface will be passed: * `array $scopeSettings, $currentScope, ContextualizerInterface $contextualizer` * * @throws \InvalidArgumentException */ public function mapConfig(array $config, $mapper) { $mapperCallable = is_callable($mapper); if (!$mapperCallable && !$mapper instanceof ConfigurationMapperInterface) { throw new InvalidArgumentException('Configuration mapper must either be a callable or an instance of ConfigurationMapper.'); } if ($mapper instanceof HookableConfigurationMapperInterface) { $mapper->preMap($config, $this->contextualizer); } $scopeNodeName = $this->contextualizer->getSiteAccessNodeName(); foreach ($config[$scopeNodeName] as $currentScope => &$scopeSettings) { if ($mapperCallable) { call_user_func_array($mapper, array($scopeSettings, $currentScope, $this->contextualizer)); } else { $mapper->mapConfig($scopeSettings, $currentScope, $this->contextualizer); } } if ($mapper instanceof HookableConfigurationMapperInterface) { $mapper->postMap($config, $this->contextualizer); } }