Skip to content

Commit c8ddf3c

Browse files
[Config][DependencyInjection] Deprecate the fluent PHP format for semantic configuration
1 parent 2ba0863 commit c8ddf3c

File tree

7 files changed

+10
-15
lines changed

7 files changed

+10
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CHANGELOG
1616
* Deprecate using `$this` or its internal scope from PHP config files; use the `$loader` variable instead
1717
* Deprecate XML configuration format, use YAML or PHP instead
1818
* Deprecate `ExtensionInterface::getXsdValidationBasePath()` and `getNamespace()`
19+
* Deprecate the fluent PHP format for semantic configuration, instantiate builders inline with the config array as argument and return them instead
1920

2021
7.3
2122
---

Loader/PhpFileLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ private function callConfigurator(callable $callback, ContainerConfigurator $con
253253
} catch (InvalidArgumentException|\LogicException $e) {
254254
throw new \InvalidArgumentException(\sprintf('Could not resolve argument "%s" for "%s".', $type.' $'.$parameter->getName(), $path), 0, $e);
255255
}
256+
trigger_deprecation('symfony/dependency-injection', '7.4', 'Using fluent builders for semantic configuration is deprecated, instantiate the "%s" class with the config array as argument and return it instead in "%s".', $type, $path);
256257
$configBuilders[] = $configBuilder;
257258
$arguments[] = $configBuilder;
258259
}

Tests/Fixtures/config/config_builder_env_configurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
use Symfony\Component\DependencyInjection\Tests\Fixtures\AcmeConfig;
44
use function Symfony\Component\DependencyInjection\Loader\Configurator\env;
55

6-
return function (AcmeConfig $config) {
7-
$config->color(env('COLOR'));
6+
return function () {
7+
return new AcmeConfig(['color' => env('COLOR')]);
88
};

Tests/Fixtures/config/env_param.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
use Symfony\Component\DependencyInjection\Tests\Fixtures\AcmeConfig;
44

5-
return function (AcmeConfig $config, string $env) {
6-
if ('prod' === $env) {
7-
$config->color('blue');
8-
} else {
9-
$config->color('red');
10-
}
5+
return function (string $env) {
6+
return new AcmeConfig(['color' => 'prod' === $env ? 'blue' : 'red']);
117
};

Tests/Fixtures/config/nested_config_builder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
return;
77
}
88

9-
return function (AcmeConfig $config) {
10-
$config->color('red');
11-
};
9+
return new AcmeConfig(['color' => 'red']);

Tests/Fixtures/config/return_config_builder.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
use Symfony\Component\DependencyInjection\Tests\Fixtures\AcmeConfig;
44

5-
$config = new AcmeConfig();
6-
$config->color('red');
7-
8-
return $config;
5+
return new AcmeConfig(['color' => 'red']);

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ public function testEnumeration()
251251
$this->assertSame([FooUnitEnum::BAR], $definition->getArguments());
252252
}
253253

254+
#[IgnoreDeprecations]
255+
#[Group('legacy')]
254256
public function testNestedBundleConfigNotAllowed()
255257
{
256258
$fixtures = realpath(__DIR__.'/../Fixtures');

0 commit comments

Comments
 (0)