Skip to content

Commit c7ecf67

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: [DI] Fix infinite loop in InlineServiceDefinitionsPass Do not cache cache attributes if `attributes` is in the context Test that it do not remove the new flashes when displaying the existing ones [HttpFoundation] AutExpireFlashBag should not clear new flashes [FrameworkBundle][Serializer] Remove YamlEncoder definition if Yaml component isn't installed [DI] Fix tracking of env vars in exceptions [Form] Don't rely on if http-foundation isn't in FileType Fix merge substitute aliases in inline mappings added ability for substitute aliases when mapping in YAML is on single line [Console] Fix global console flag when used in chain
2 parents 784a6fc + ecbd330 commit c7ecf67

File tree

4 files changed

+73
-15
lines changed

4 files changed

+73
-15
lines changed

Compiler/InlineServiceDefinitionsPass.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ protected function processValue($value, $isRoot = false)
6565
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
6666
$this->inlinedServiceIds[$id][] = $this->currentId;
6767

68-
if ($definition->isShared()) {
69-
return $definition;
70-
}
71-
$value = clone $definition;
68+
return $definition->isShared() ? $definition : clone $definition;
7269
}
7370
}
7471

Compiler/MergeExtensionConfigurationPass.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,26 @@ public function process(ContainerBuilder $container)
5656
}
5757
$config = $resolvingBag->resolveValue($config);
5858

59-
$tmpContainer = new MergeExtensionConfigurationContainerBuilder($extension, $resolvingBag);
60-
$tmpContainer->setResourceTracking($container->isTrackingResources());
61-
$tmpContainer->addObjectResource($extension);
62-
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
63-
$tmpContainer->addObjectResource($configuration);
64-
}
59+
try {
60+
$tmpContainer = new MergeExtensionConfigurationContainerBuilder($extension, $resolvingBag);
61+
$tmpContainer->setResourceTracking($container->isTrackingResources());
62+
$tmpContainer->addObjectResource($extension);
63+
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
64+
$tmpContainer->addObjectResource($configuration);
65+
}
6566

66-
foreach ($exprLangProviders as $provider) {
67-
$tmpContainer->addExpressionLanguageProvider($provider);
68-
}
67+
foreach ($exprLangProviders as $provider) {
68+
$tmpContainer->addExpressionLanguageProvider($provider);
69+
}
6970

70-
$extension->load($config, $tmpContainer);
71+
$extension->load($config, $tmpContainer);
72+
} catch (\Exception $e) {
73+
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
74+
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
75+
}
76+
77+
throw $e;
78+
}
7179

7280
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
7381
// don't keep track of env vars that are *overridden* when configs are merged

Tests/Compiler/InlineServiceDefinitionsPassTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ public function testProcessDoesInlineNonSharedService()
9292
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
9393
}
9494

95+
public function testProcessInlinesMixedServicesLoop()
96+
{
97+
$container = new ContainerBuilder();
98+
$container
99+
->register('foo')
100+
->addArgument(new Reference('bar'))
101+
->setShared(false)
102+
;
103+
$container
104+
->register('bar')
105+
->setPublic(false)
106+
->addMethodCall('setFoo', array(new Reference('foo')))
107+
;
108+
109+
$this->process($container);
110+
111+
$this->assertEquals($container->getDefinition('foo')->getArgument(0), $container->getDefinition('bar'));
112+
}
113+
95114
public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
96115
{
97116
$container = new ContainerBuilder();

Tests/Compiler/MergeExtensionConfigurationPassTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,26 @@ public function testProcessedEnvsAreIncompatibleWithResolve()
110110
{
111111
$container = new ContainerBuilder();
112112
$container->registerExtension(new BarExtension());
113-
$container->prependExtensionConfig('bar', array());
113+
$container->prependExtensionConfig('bar', []);
114114

115115
(new MergeExtensionConfigurationPass())->process($container);
116116
}
117+
118+
public function testThrowingExtensionsGetMergedBag()
119+
{
120+
$container = new ContainerBuilder();
121+
$container->registerExtension(new ThrowingExtension());
122+
$container->prependExtensionConfig('throwing', array('bar' => '%env(FOO)%'));
123+
124+
try {
125+
$pass = new MergeExtensionConfigurationPass();
126+
$pass->process($container);
127+
$this->fail('An exception should have been thrown.');
128+
} catch (\Exception $e) {
129+
}
130+
131+
$this->assertSame(array('FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
132+
}
117133
}
118134

119135
class FooConfiguration implements ConfigurationInterface
@@ -163,3 +179,21 @@ public function load(array $configs, ContainerBuilder $container)
163179
$container->resolveEnvPlaceholders('%env(int:FOO)%', true);
164180
}
165181
}
182+
183+
class ThrowingExtension extends Extension
184+
{
185+
public function getAlias()
186+
{
187+
return 'throwing';
188+
}
189+
190+
public function getConfiguration(array $config, ContainerBuilder $container)
191+
{
192+
return new FooConfiguration();
193+
}
194+
195+
public function load(array $configs, ContainerBuilder $container)
196+
{
197+
throw new \Exception();
198+
}
199+
}

0 commit comments

Comments
 (0)