8000 bug #57937 [DependencyInjection] Fix importing PHP configs in the pre… · symfony/symfony@5abfba2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5abfba2

Browse files
bug #57937 [DependencyInjection] Fix importing PHP configs in the prepend extension method (yceruto)
This PR was merged into the 7.1 branch. Discussion ---------- [DependencyInjection] Fix importing PHP configs in the prepend extension method | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57936 | License | MIT I missed this nesting case during #52843. Commits ------- 94df570 Fix importing PHP config in prepend extension method
2 parents 0c91466 + 94df570 commit 5abfba2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function import(mixed $resource, ?string $type = null, bool|string $ignor
9292
}
9393
} finally {
9494
--$this->importing;
95+
$this->loadExtensionConfigs();
9596
}
9697

9798
return null;

src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ private function executeCallback(callable $callback, ContainerConfigurator $cont
143143
// Force load ContainerConfigurator to make env(), param() etc available.
144144
class_exists(ContainerConfigurator::class);
145145

146-
$callback(...$arguments);
146+
++$this->importing;
147+
try {
148+
$callback(...$arguments);
149+
} finally {
150+
--$this->importing;
151+
}
147152

148153
foreach ($configBuilders as $configBuilder) {
149154
$this->loadExtensionConfig($configBuilder->getExtensionAlias(), ContainerConfigurator::processValue($configBuilder->toArray()));

src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testLoad()
4747
$this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a PHP file resource');
4848
}
4949

50-
public function testPrependExtensionConfig()
50+
public function testPrependExtensionConfigWithLoadMethod()
5151
{
5252
$container = new ContainerBuilder();
5353
$container->registerExtension(new \AcmeExtension());
@@ -63,6 +63,22 @@ public function testPrependExtensionConfig()
6363
$this->assertSame($expected, $container->getExtensionConfig('acme'));
6464
}
6565

66+
public function testPrependExtensionConfigWithImportMethod()
67+
{
68+
$container = new ContainerBuilder();
69+
$container->registerExtension(new \AcmeExtension());
70+
$container->prependExtensionConfig('acme', ['foo' => 'bar']);
71+
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures'), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()), true);
72+
$loader->import('config/config_builder.php');
73+
74+
$expected = [
75+
['color' => 'red'],
76+
['color' => 'blue'],
77+
['foo' => 'bar'],
78+
];
79+
$this->assertSame($expected, $container->getExtensionConfig('acme'));
80+
}
81+
6682
public function testConfigServices()
6783
{
6884
$fixtures = realpath(__DIR__.'/../Fixtures');

0 commit comments

Comments
 (0)
0