Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Routing] Use env() in route condition#35727

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

atailouloute
Copy link
Contributor

@atailoulouteatailouloute commentedFeb 14, 2020
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
Deprecations?no
Tickets
LicenseMIT
Doc PRTODO

Added anExpressionLanguageProvider in the Routing component, that provides theenv function which could be used in route conditions

An example of the feature

/** * @Route("/only-for-dev", condition="env('APP_ENV') === 'dev'") */publicfunction__invoke(){echo"This will be executed only when APP_ENV = dev";}

With a default value:

/** * @Route("/only-for-dev", condition="env('APP_ENV', 'dev') === 'dev'") */

Copy link
Contributor

@HeahDudeHeahDude left a 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

atailouloute reacted with thumbs up emoji
@HeahDude
Copy link
Contributor

Side note: the idea of using the expression language is to have a workaround the current%env()% usage limitation with routes definition.

@nicolas-grekasnicolas-grekas added this to thenext milestoneFeb 14, 2020
@stof
Copy link
Member

AFAICT, the service definition is useless for now, as it is not wired in the routing component at all.

@nicolas-grekas
Copy link
Member

I think this doesn't work: reading$_SERVER is not the same as using%env()% (because of env processors + env loaders). People will expect those to be the same.

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%env()% reference from some config file)

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 :) )

@atailouloute
Copy link
ContributorAuthor

atailouloute commentedFeb 14, 2020
edited
Loading

AFAICT, the service definition is useless for now, as it is not wired in the routing component at all.

@stof, It is wired to Routing, there was already a compiler pass that does that
https://github.com/symfony/framework-bundle/blob/master/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.php#L31

fabpot added a commit that referenced this pull requestFeb 25, 2020
…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        | TODOThis 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 testsCommits-------b574460 [Routing][FrameworkBundle] Allow using env() in route conditions
@nicolas-grekasnicolas-grekas modified the milestones:next,5.1May 4, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@HeahDudeHeahDudeHeahDude left review comments

Assignees
No one assigned
Projects
None yet
Milestone
5.1
Development

Successfully merging this pull request may close these issues.

5 participants
@atailouloute@HeahDude@stof@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp