8000 [DependencyInjection] Fix importing PHP configs in the prepend extension method by yceruto · Pull Request #57937 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Fix importing PHP configs in the prepend extension method #57937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function import(mixed $resource, ?string $type = null, bool|string $ignor
}
} finally {
--$this->importing;
$this->loadExtensionConfigs();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this here (even in case of exception) ?

8000 Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because there is a return statement inside the try block, so there is no other chance to load the collected ext config after --$this->importing; instruction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, it's not about the exception at all, but if it happens I guess it doesn't matter if we try to prepend some configs afterward

}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ private function executeCallback(callable $callback, ContainerConfigurator $cont
// Force load ContainerConfigurator to make env(), param() etc available.
class_exists(ContainerConfigurator::class);

$callback(...$arguments);
++$this->importing;
try {
$callback(...$arguments);
} finally {
--$this->importing;
}

foreach ($configBuilders as $configBuilder) {
$this->loadExtensionConfig($configBuilder->getExtensionAlias(), ContainerConfigurator::processValue($configBuilder->toArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testLoad()
$this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a PHP file resource');
}

public function testPrependExtensionConfig()
public function testPrependExtensionConfigWithLoadMethod()
{
$container = new ContainerBuilder();
$container->registerExtension(new \AcmeExtension());
Expand All @@ -63,6 +63,22 @@ public function testPrependExtensionConfig()
$this->assertSame($expected, $container->getExtensionConfig('acme'));
}

public function testPrependExtensionConfigWithImportMethod()
{
$container = new ContainerBuilder();
$container->registerExtension(new \AcmeExtension());
$container->prependExtensionConfig('acme', ['foo' => 'bar']);
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures'), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()), true);
$loader->import('config/config_builder.php');

$expected = [
['color' => 'red'],
['color' => 'blue'],
['foo' => 'bar'],
];
$this->assertSame($expected, $container->getExtensionConfig('acme'));
}

public function testConfigServices()
{
$fixtures = realpath(__DIR__.'/../Fixtures');
Expand Down
0