Skip to content

Commit 725b56c

Browse files
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 Processor
2 parents fdecdd4 + 2becd93 commit 725b56c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
17221722
}
17231723

17241724
if ($config['decryption_env_var']) {
1725-
if (!preg_match('/^(?:[-.\w]*+:)*+\w++$/', $config['decryption_env_var'])) {
1725+
if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w++$/', $config['decryption_env_var'])) {
17261726
throw new InvalidArgumentException(sprintf('Invalid value "%s" set as "decryption_env_var": only "word" characters are allowed.', $config['decryption_env_var']));
17271727
}
17281728

0 commit comments

Comments
 (0)