You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #62092 [Config][DependencyInjection] Deprecate the fluent PHP format for semantic configuration (nicolas-grekas)
This PR was merged into the 7.4 branch.
Discussion
----------
[Config][DependencyInjection] Deprecate the fluent PHP format for semantic configuration
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
This PR deprecates the fluent PHP format for semantic configuration introduced in Symfony 5.4 by `@Nyholm` (see #40600).
It aims to replace it with the new array-based PHP config format (see #61490).
The fluent PHP config format was a great experiment:
- It helped us improve the Config component and the code generation of fluent config builders.
- It confirmed the community’s interest in PHP-based configuration.
- And it showed us its limits.
Those limits are structural. Writing fluent config is difficult and full of edge cases. Its rigidity comes from having to match one canonical interpretation of the semantic config tree. Automatic code generation can’t capture the custom logic that before-normalizers introduce, yet those normalizers are essential for flexibility and backward compatibility. This rigidity makes fluent config fragile. How do we deal with this fragility as config tree authors? At the moment, we don't care. Maybe this format is too niche for you to have experienced this issue, but we cannot guarantee that simple upgrades won't break your fluent PHP config.
The new array-based PHP format builds directly on the same code used for loading YAML configs.
That means:
- trivial conversion between YAML and PHP arrays,
- identical flexibility and behavior,
- and support for auto-completion and static analysis through generated array shapes.
The generated array shapes are rigid too, but that rigidity is non-breaking: even if your config no longer matches the canonical shape, your app keeps working. Static analyzers might warn you: that’s an invitation to update, not a failure.
I'm submitting this PR a bit l late for 7.4 but I think it's important to merge now. Deprecating the fluent PHP config format will:
- prevent new code from relying on a fragile approach,
- make room in the documentation for the array-based format,
- and consolidate Symfony’s configuration story around a robust PHP-based format.
Fluent PHP for semantic config served us well but it's time to retire it.
```diff
-return function (AcmeConfig $config) {
- $config->color('red');
-}
+return new AcmeConfig([
+ 'color' => 'red',
+]);
```
PS: there's another fluent config format for services and routes (see #23834 and #24180). This other format is handwritten. It doesn't have the issues listed above and it is *not* deprecated. It's actually the recommended way *for bundles* to declare their config (instead of XML, see #60568).
Commits
-------
332b4ac [Config][DependencyInjection] Deprecate the fluent PHP format for semantic configuration
trigger_deprecation('symfony/config', '7.4', 'Calling any fluent method on \"%s\" is deprecated; pass the configuration to the constructor instead.', \$this::class);
540
+
}";
541
+
}
542
+
512
543
$class->addMethod('toArray', '
513
544
public function NAME(): array
514
545
{
@@ -583,13 +614,16 @@ private function buildSetExtraKey(ClassBuilder $class): void
583
614
* @param ParamConfigurator|mixed $value
584
615
*
585
616
* @return $this
586
-
*/
617
+
*DEPRECATED_ANNOTATION/
587
618
public function NAME(string $key, mixed $value): static
0 commit comments