Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ComplexSettingsPass.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
8
9 use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ComplexSettings\ComplexSettingParserInterface;
10 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11 use Symfony\Component\DependencyInjection\ContainerBuilder;
12 use Symfony\Component\ExpressionLanguage\Expression;
13
14 class ComplexSettingsPass implements CompilerPassInterface
15 {
17 private $parser;
18
19 public function __construct(ComplexSettingParserInterface $parser)
20 {
21 $this->parser = $parser;
22 }
23
24 public function process(ContainerBuilder $container)
25 {
26 foreach ($container->getDefinitions() as $serviceId => $definition) {
27 $arguments = $definition->getArguments();
28 foreach ($arguments as $argumentIndex => $argumentValue) {
29 if (!is_string($argumentValue)) {
30 continue;
31 }
32
33 if (!$this->parser->containsDynamicSettings($argumentValue)) {
34 continue;
35 }
36
37 if ($this->parser->isDynamicSetting($argumentValue)) {
38 continue;
39 }
40
41 $arguments[$argumentIndex] = $this->createComplexSettingExpression(
42 $argumentValue,
43 $this->parser->parseComplexSetting($argumentValue)
44 );
45 }
46
47 $definition->setArguments($arguments);
48 }
49 }
50
64 private function createComplexSettingExpression($argumentValue, array $dynamicSettings)
65 {
66 $resolverArguments = ['"' . $argumentValue . '"'];
67 foreach ($dynamicSettings as $dynamicSetting) {
68 // Trim the '$' so that the dynamic setting doesn't get transformed
69 $resolverArguments[] = '"' . trim($dynamicSetting, '$') . '"';
70 // This one will be transformed
71 $resolverArguments[] = $this->createConfigResolverSubExpression(
72 $this->parser->parseDynamicSetting($dynamicSetting)
73 );
74 }
75
76 $expression = sprintf(
77 'service("ezpublish.config.complex_setting_value.resolver").resolveSetting(%s)',
78 implode(', ', $resolverArguments)
79 );
80
81 return new Expression($expression);
82 }
83
91 private function createConfigResolverSubExpression(array $parsedDynamicSetting)
92 {
93 $expression = sprintf(
94 'service("ezpublish.config.resolver").getParameter("%s", %s, %s)',
95 $parsedDynamicSetting['param'],
96 isset($parsedDynamicSetting['namespace']) ? '"' . $parsedDynamicSetting['namespace'] . '"' : 'null',
97 isset($parsedDynamicSetting['scope']) ? '"' . $parsedDynamicSetting['scope'] . '"' : 'null'
98 );
99
100 return $expression;
101 }
102 }
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ComplexSettingsPass
Definition: ComplexSettingsPass.php:15
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ComplexSettingsPass\__construct
__construct(ComplexSettingParserInterface $parser)
Definition: ComplexSettingsPass.php:19
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ComplexSettingsPass\$parser
$parser
Definition: ComplexSettingsPass.php:17
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ComplexSettingsPass\createConfigResolverSubExpression
createConfigResolverSubExpression(array $parsedDynamicSetting)
Returns the sub expression (as string) to resolve individual dynamic settings contained in original c...
Definition: ComplexSettingsPass.php:91
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ComplexSettingsPass\createComplexSettingExpression
createComplexSettingExpression($argumentValue, array $dynamicSettings)
Creates an expression for given complex setting.
Definition: ComplexSettingsPass.php:64
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ComplexSettingsPass\process
process(ContainerBuilder $container)
Definition: ComplexSettingsPass.php:24
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ComplexSettings\ComplexSettingParserInterface
Parses a string that contains dynamic settings ($foo;eng;bar$).
Definition: ComplexSettingParserInterface.php:17
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler
Definition: AsseticPass.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.