Commit 725b56c
committed
feature #46564 [DependencyInjection] Add Enum Env Var Processor (jack-worman)
This PR was merged into the 6.2 branch.
Discussion
----------
[DependencyInjection] Add Enum Env Var Processor
| Q | A
| ------------- | ---
| Branch? | 6.2
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | N/A
| License | MIT
| Doc PR | waiting on approval of feature
Add the ability to transform env variables into \BackedEnums.
For example, you could now autowire an enum from an environment variable:
```php
<?php
use Symfony\Component\DependencyInjection\Attribute\Autowire;
enum AppEnv: string {
case Test = 'test';
case Dev = 'dev';
case Stage = 'stage';
case Prod = 'prod';
}
class Foo {
public function __construct(
#[Autowire('%env(enum:'.AppEnv::class.':APP_ENV)%')]
private AppEnv $appEnv,
) {}
}
```
Commits
-------
41e22723c4 Add Enum Env Var Processor1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1722 | 1722 | | |
1723 | 1723 | | |
1724 | 1724 | | |
1725 | | - | |
| 1725 | + | |
1726 | 1726 | | |
1727 | 1727 | | |
1728 | 1728 | | |
| |||
0 commit comments