Skip to content
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

[DependencyInjection] Add an env function to DI expression language #45450

Merged
merged 1 commit into from Feb 18, 2022

Conversation

jvasseur
Copy link
Contributor

@jvasseur jvasseur commented Feb 16, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#16518

This add an env function to the DI expression language provider to ease creating expressions that depends on an environment variable.

@@ -1586,7 +1586,7 @@ private function getExpressionLanguage(): ExpressionLanguage
if (!class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders, null, \Closure::fromCallable([$this, 'getEnv']));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only way I found to allow the expression language to fetch an env variable outside of a dumped container because of the getEnv visibility but maybe we could make the method public instead.

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.

Nice, I like it :)

@carsonbot carsonbot changed the title Add an env function to DI expression language [DependencyInjection] Add an env function to DI expression language Feb 18, 2022
@nicolas-grekas
Copy link
Member

Thank you @jvasseur.

@nicolas-grekas nicolas-grekas merged commit 65b7fa1 into symfony:6.1 Feb 18, 2022
@jvasseur jvasseur deleted the expr-env branch February 18, 2022 10:23
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Mar 11, 2022
…xpression function (jvasseur)

This PR was merged into the 6.1 branch.

Discussion
----------

[DependencyInjection] Add documentation for the env DI expression function

Doc PR for symfony/symfony#45450

Commits
-------

bcbf1f3 Add documentation for the env DI expresion function
@fabpot fabpot mentioned this pull request Apr 15, 2022
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.

None yet

3 participants