/** * Creates an expression for given complex setting. * * The expression uses 'ezpublish.config.complex_setting_value.resolver' service for complex setting resolution. * The complex setting value resolver has a variable number of arguments. * Dynamic settings are added as tuples: first the argument without the leading and trailing $, so that it is not * transformed by the config resolver pass, then the argument as a string, so that it does get transformed. * * @param string $argumentValue The original argument ($var$/$another_var$) * @param array $dynamicSettings Array of dynamic settings in $argumentValue * * @return Expression */ private function createComplexSettingExpression($argumentValue, array $dynamicSettings) { $resolverArguments = ['"' . $argumentValue . '"']; foreach ($dynamicSettings as $dynamicSetting) { // Trim the '$' so that the dynamic setting doesn't get transformed $resolverArguments[] = '"' . trim($dynamicSetting, '$') . '"'; // This one will be transformed $resolverArguments[] = $this->createConfigResolverSubExpression($this->parser->parseDynamicSetting($dynamicSetting)); } $expression = sprintf('service("ezpublish.config.complex_setting_value.resolver").resolveSetting(%s)', implode(', ', $resolverArguments)); return new Expression($expression); }
private function postProcessComplexSetting($setting, $sa, ContainerBuilder $container) { $configResolver = $container->get('ezpublish.config.resolver.core'); if (!$configResolver->hasParameter($setting, null, $sa)) { return false; } $settingValue = $configResolver->getParameter($setting, null, $sa); if (!$this->complexSettingParser->containsDynamicSettings($settingValue)) { return false; } // we kind of need to process this as well, don't we ? if ($this->complexSettingParser->isDynamicSetting($settingValue)) { $parts = $this->complexSettingParser->parseDynamicSetting($settingValue); if (!isset($parts['namespace'])) { $parts['namespace'] = 'ezsettings'; } if (!isset($parts['scope'])) { $parts['scope'] = $sa; } return $configResolver->getParameter($parts['param'], null, $sa); } $value = $settingValue; foreach ($this->complexSettingParser->parseComplexSetting($settingValue) as $dynamicSetting) { $parts = $this->complexSettingParser->parseDynamicSetting($dynamicSetting); if (!isset($parts['namespace'])) { $parts['namespace'] = 'ezsettings'; } if (!isset($parts['scope'])) { $parts['scope'] = $sa; } $dynamicSettingValue = $configResolver->getParameter($parts['param'], $parts['namespace'], $parts['scope']); $value = str_replace($dynamicSetting, $dynamicSettingValue, $value); } return $value; }
public function process(ContainerBuilder $container) { foreach ($container->getDefinitions() as $serviceId => $definition) { $arguments = $definition->getArguments(); foreach ($arguments as $argumentIndex => $argumentValue) { if (!is_string($argumentValue)) { continue; } if (!$this->parser->containsDynamicSettings($argumentValue)) { continue; } if ($this->parser->isDynamicSetting($argumentValue)) { continue; } $factoryServiceId = sprintf('%s.%s_%d', $serviceId, '__complex_setting_factory', $argumentIndex); $container->setDefinition($factoryServiceId, $this->createFactoryDefinition($argumentValue, $this->parser->parseComplexSetting($argumentValue))); $arguments[$argumentIndex] = new Reference($factoryServiceId); $definition->setArguments($arguments); } } }