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 #47801 [DependencyInjection] Allow array for the value of Autowire attribute (willemverspyck)
This PR was squashed before being merged into the 6.2 branch.
Discussion
----------
[DependencyInjection] Allow array for the value of Autowire attribute
| Q | A
| ------------- | ---
| Branch? | 6.2
| Bug fix? | no
| New feature? | yes
| Deprecations? |no
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the latest branch.
- For new features, provide some code snippets to help understand usage.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
Since Symfony 6.1 it's possible to use #[Autowire] for the service autowiring logic. Array as autowire parameters is not supported yet. In YAML or the attribute Autoconfigure it worked.
```php
#[Autoconfigure(bind: [
'$parameters' => [
'PARAMETER_DAY_START' => '%env(string:PARAMETER_DAY_START)%',
'PARAMETER_DAY_END' => '%env(string:PARAMETER_DAY_END)%',
'FILTER_LIMIT' => '%env(int:FILTER_LIMIT)%',
'FILTER_OFFSET' => '%env(int:FILTER_OFFSET)%',
],
])]
class WidgetService
{
public function __construct(private readonly array $parameters)
{
}
}
```
After this PR there is support for an array (including some extra tests):
```php
class WidgetService
{
public function __construct(#[Autowire([
'PARAMETER_DAY_START' => '%env(string:PARAMETER_DAY_START)%',
'PARAMETER_DAY_END' => '%env(string:PARAMETER_DAY_END)%',
'FILTER_LIMIT' => '%env(int:FILTER_LIMIT)%',
'FILTER_OFFSET' => '%env(int:FILTER_OFFSET)%',
])] private readonly array $parameters)
{
}
}
```
Commits
-------
e983f64aee [DependencyInjection] Allow array for the value of Autowire attribute
0 commit comments