-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Use env() in route condition #35727
New is 8000 sue
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
[Routing] Use env() in route condition #35727
Conversation
d71b869
to
bb3ed99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this
src/Symfony/Component/Routing/Matcher/ExpressionLanguageProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Routing/Matcher/ExpressionLanguageProvider.php
Outdated
Show resolved
Hide resolved
Side note: the idea of using the expression language is to have a workaround the current |
bb3ed99
to
9961615
Compare
9961615
to
440aad7
Compare
440aad7
to
b2a5967
Compare
AFAICT, the service definition is useless for now, as it is not wired in the routing component at all. |
I think this doesn't work: reading Instead, I'd suggest to find a way to pre-declare extra key=>value pairs that would be available to conditions (whom values could come from a real We just talked about this on Slack with @HeahDude, I invite you to get in touch with him for details (as he's the one pushing for this to happen :) ) |
@stof, It is wired to Routing, there was already a compiler pass that does that |
…conditions (atailouloute) This PR was merged into the 5.1-dev branch. Discussion ---------- [Routing][FrameworkBundle] Allow using env() in route conditions | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | TODO This is a second implementation of #35727, it overcomes the limitation mentioned by nicolas in (#35727 (comment)) The goal of this feature is to be able to use env variables in Route conditions ```php /** * @route("/only-for-dev", condition="env('APP_ENV') === 'dev'") */ public function __invoke() { echo "This will be executed only when APP_ENV = dev"; } ``` it supports also env processors/ loaders ```php /** * @route("/only-for-dev", condition="env('trim:APP_ENV') === 'dev'") */ ```` **TODOs:** - [x] Complete unit tests Commits ------- b574460 [Routing][FrameworkBundle] Allow using env() in route conditions
Added an
ExpressionLanguageProvider
in the Routing component, that provides theenv
function which could be used in route conditionsAn example of the feature
With a default value: