Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Allow injecting the current env into php config closures #47906

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
Oct 19, 2022

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented Oct 18, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? yes
Tickets -
License MIT
Doc PR -

The original idea of this PR was to allow injecting string $env into php config closures. Even though this can be done by injecting ContainerConfigurator & calling env() it seems kind of redundant when you don't need any features except the current env, eg when using the config builder classes:

- return function (AcmeConfig $config, ContainerConfigurator $c) {
+ return function (AcmeConfig $config, string $env) {
- if ('dev' === $c->env()) {
+ if ('dev' === $env) {
    // ...
  }
};

Injecting the $env variable looks a bit cleaner IMO.

However, while working on this PR I discovered #41182 . Even though there's already an $env variable presets in the scope of php files which can be used for the same thing, it's not really IDE friendly:

image

Since the original PR mentioned the that the $env variable was added for PHP <8 & Symfony 6.2 is >=8.1, it doesn't seem to be needed any more, so it can be deprecated.

@carsonbot carsonbot added this to the 6.2 milestone Oct 18, 2022
@carsonbot carsonbot changed the title [DI] Allow injecting the current env into php config closures [DependencyInjection] Allow injecting the current env into php config closures Oct 18, 2022
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, except the deprecation, which is not needed.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(rebase needed)

@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

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