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] Add params variable to condition expression#46042

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

Merged
fabpot merged 1 commit intosymfony:6.1fromHypeMC:route-params-in-conditions
Apr 21, 2022

Conversation

@HypeMC
Copy link
Member

@HypeMCHypeMC commentedApr 14, 2022
edited
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?yes
Tickets-
LicenseMIT
Doc PRsymfony/symfony-docs#16747

Currently it's not possible to userequest.attributes.get('_route_params') in route conditions because the parameter is not yet set when the expression is being evaluated. That happensafter the matcher is finished.

This PR adds a newparams variable to the condition option expression syntax:

class FooController{    #[Route('/foo/{id}', requirements: ['id' =>'\d+'], condition:"params['id'] < 100")]publicfunctionindex(int$id):Response    {    }}

GromNaN reacted with thumbs up emoji
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks, that's a nice feature, and the implementation is perfect. This leaves me only bike-shedding :D

So: what about injecting the parameter as variables directly in the expression? eg
#[Route('/foo/{id}', requirements: ['id' => '\d+'], condition: "id < 100")]

Of course we should then forbid to use context/request as var names, or at least give them higher priority.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedApr 19, 2022
edited
Loading

Or maybe just renameroute_parameters toparams?
#[Route('/foo/{id}', requirements: ['id' => '\d+'], condition: "params.id < 100")]

@nicolas-grekasnicolas-grekas modified the milestones:6.1,6.2Apr 19, 2022
@HypeMCHypeMCforce-pushed theroute-params-in-conditions branch from50fa6ef toacefeb9CompareApril 19, 2022 10:17
@HypeMC
Copy link
MemberAuthor

Thanks, that's a nice feature, and the implementation is perfect. This leaves me only bike-shedding :D

So: what about injecting the parameter as variables directly in the expression? eg#[Route('/foo/{id}', requirements: ['id' => '\d+'], condition: "id < 100")]

Of course we should then forbid to use context/request as var names, or at least give them higher priority.

Or maybe just renameroute_parameters toparams? #[Route('/foo/{id}', requirements: ['id' => '\d+'], condition: "params.id < 100")]

Thanks for the review, I'verenamed the variable toparams. I like the idea of injecting the parameters as variables as well, but as you mentioned, that might cause collisions with var names. This seems like the safer option, but if you want, I can inject them instead, I'm fine either way.

@HypeMCHypeMC changed the title[Routing] Add route_parameters variable to condition expression[Routing] Add params variable to condition expressionApr 19, 2022
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

To the next reviewer: please help us answer this open question above :)

@stof
Copy link
Member

I prefer injecting aparams variable.
From prior experience in the@Security annotation of FrameworkExtraBundle, mixing predefined variables and user-defined variable names in the same expression is a mess regarding conflicts (and still requires injecting a variable allowing to access params that could not be injected as variables due to the conflict, with a weird DX when a few param names need a special access pattern, and a forever-freeze of the list of predefined variables to avoid BC breaks)

@Tobion
Copy link
Contributor

I agree with stof.

@Tobion
Copy link
Contributor

I think it would be ok to still release this in 6.1 before the RC. It fits with#44405 and it would make sense to document/new in symfony this together.

---

* Add`params` variable to condition expression
* Deprecate not passing route parameters as the forth argument to`UrlMatcher::handleRouteRequirements()`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Deprecate not passing route parameters as theforth argument to`UrlMatcher::handleRouteRequirements()`
* Deprecate not passing route parameters as thefourth argument to`UrlMatcher::handleRouteRequirements()`

@fabpotfabpot modified the milestones:6.2,6.1Apr 21, 2022
@fabpot
Copy link
Member

Thank you@HypeMC.

@fabpotfabpot merged commit4e39d25 intosymfony:6.1Apr 21, 2022
@HypeMCHypeMC deleted the route-params-in-conditions branchApril 21, 2022 06:24
HypeMC added a commit to HypeMC/symfony that referenced this pull requestApr 21, 2022
Tobion added a commit that referenced this pull requestApr 21, 2022
…(HypeMC)This PR was merged into the 6.1 branch.Discussion----------[Routing] Fix changelog & deprecation message for#46042| Q             | A| ------------- | ---| Branch?       | 6.1| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -Since#46042 was merged into 6.1 the changelog & deprecation message are now wrong. cc `@fabpot`Commits-------bb37826 [Routing] Fix changelog & deprecation message for#46042
@fabpotfabpot mentioned this pull requestApr 27, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@TobionTobionTobion approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

6 participants

@HypeMC@nicolas-grekas@stof@Tobion@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp