Skip to content

Commit

Permalink
bug #54970 [DependencyInjection] Process PHP configs using the Contai…
Browse files Browse the repository at this point in the history
…nerConfigurator (MatTheCat)

This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection] Process PHP configs using the ContainerConfigurator

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54852
| License       | MIT

Since #52843, `ContainerConfigurator::extension` is not called anymore which means `ParamConfigurator`s are no longer processed and converted to strings, and make nodes validation fail: e.g. `framework.secret` would receive an `EnvConfigurator` and throw because it is not a scalar.

Commits
-------

e6dc6be [DependencyInjection] Process PHP configs using the ContainerConfigurator
  • Loading branch information
nicolas-grekas committed May 17, 2024
2 parents c58c599 + e6dc6be commit 4e01371
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,8 @@ class_exists(ContainerConfigurator::class);

$callback(...$arguments);

$this->loadFromExtensions($configBuilders);
}

/**
* @param iterable<ConfigBuilderInterface> $configBuilders
*/
private function loadFromExtensions(iterable $configBuilders): void
{
foreach ($configBuilders as $configBuilder) {
$this->loadExtensionConfig($configBuilder->getExtensionAlias(), $configBuilder->toArray());
$containerConfigurator->extension($configBuilder->getExtensionAlias(), $configBuilder->toArray(), $this->prepend);
}

$this->loadExtensionConfigs();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use Symfony\Component\DependencyInjection\Tests\Fixtures\AcmeConfig;
use function Symfony\Component\DependencyInjection\Loader\Configurator\env;

return function (AcmeConfig $config) {
$config->color(env('COLOR'));
};
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,14 @@ public function testServiceWithServiceLocatorArgument()
$values = ['foo' => new Definition(\stdClass::class), 'bar' => new Definition(\stdClass::class)];
$this->assertEquals([new ServiceLocatorArgument($values)], $container->getDefinition('locator_dependent_inline_service')->getArguments());
}

public function testConfigBuilderEnvConfigurator()
{
$container = new ContainerBuilder();
$container->registerExtension(new \AcmeExtension());
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures'), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()), true);
$loader->load('config/config_builder_env_configurator.php');

$this->assertIsString($container->getExtensionConfig('acme')[0]['color']);
}
}

0 comments on commit 4e01371

Please sign in to comment.