Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Add Enum Env Var Processor #46564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2022
Merged

[DependencyInjection] Add Enum Env Var Processor #46564

merged 1 commit into from
Jun 27, 2022

Conversation

jack-worman
Copy link
Contributor

@jack-worman jack-worman commented Jun 2, 2022

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

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,
    ) {}
}

@carsonbot
Copy link

Hey!

I think @ruudk has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@nicolas-grekas
Copy link
Member

This might miss some pieces as I think some regexps like this one might prevent using FQCN in %env()% parameters:

@nicolas-grekas
Copy link
Member

Please update the description of the PR to make it clear what you're proposing. I could guess by looking at the tests, but providing a proper PR description is nonetheless a good thing to help ppl understand what this is about, and start the doc later on.

src/Symfony/Component/DependencyInjection/CHANGELOG.md Outdated Show resolved Hide resolved
@nicolas-grekas
Copy link
Member

A next step could be to find a way to make autowiring do its part, so that the enum: prefix wouldn't be needed.
But that's for another PR :)

👍

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 27, 2022

Can you please rebase on latest 6.2? We don't merge PRs with merge commits. If you want to squash while doing so, please do (we'll do it when merging otherwise.)

@jack-worman
Copy link
Contributor Author

Rebase and squash is done!

@nicolas-grekas
Copy link
Member

Thank you @jack-worman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.