-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Routing] Allow using services in the route condition #44405
[Routing] Allow using services in the route condition #44405
Conversation
renanbr
commented
Dec 1, 2021
•
edited
Loading
edited
Q | A |
---|---|
Branch? | 6.1 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Tickets | n/a |
License | MIT |
Doc PR | n/a |
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
95cf5ab
to
cc6df1c
Compare
...dle/FrameworkBundle/DependencyInjection/Compiler/ExpressionConditionVariableResolverPass.php
Outdated
Show resolved
Hide resolved
...dle/FrameworkBundle/DependencyInjection/Compiler/ExpressionConditionVariableResolverPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Routing/Attribute/AsRouteExpressionConditionVariable.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Routing/Attribute/AsRouteExpressionConditionVariable.php
Outdated
Show resolved
Hide resolved
On second though, we might want to go a bit further: with the current approach, referenced services are going to be instantiated all the time, while they might be needed only on very specific routes. |
What if two services are registered with the same name? This could cause some confusing issues, every service will override the one registered before. If docs will be added: prefix the service names in third party bundles. |
Instantiating services all the time is indeed not good. Based on your feedback I was wondering if we could inject a function that relies on a service locator instead of injecting variables
Pros:
What do you think? |
I like it @renanbr! |
Status: Since eafc9c5, the FrameworkBundle wraps tagged services into a I'm satisfied with this ☝🏼 solution. My next shot will be implementing |
eafc9c5
to
9759f3b
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
Why not using the |
For convenience I think. What would be the DX of your proposal? |
@renanbr up to finish this PR? |
Late it the discussion. A new function class DefaultController
{
#[Route('/page', condition: 'service('foo').bar()')]
public function page(): Response { ... }
} |
The one true container you mean? I guess that's no-go since that'd require services to be made public. The benefit of this proposal is that it allows labeling which services need to be made available for the routing layer. |
Maybe a service locator, feed with regular tagged services. |
That's exactly what this PR does IIUC :) |
Indeed. Then the description needs to be updated. |
I'll work on this week and the next week. thanks for the review btw |
9051221
to
61646a2
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.
This is so rad! Please add a few tests and we'll be good!
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php
Outdated
Show resolved
Hide resolved
3db2a42
to
2440987
Compare
updated,
|
src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php
Show resolved
Hide resolved
2440987
to
01c0a40
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.
Well done
Gather routing variables into a service locator Add service() function for route condition Add missing file Fix psalm remove routing variable concept Add tests and rename routing condition service make fabbot happy add entry in changelog
01c0a40
to
3724576
Compare
Thanks @renanbr for working on this feature, this is much appreciated. |
This PR was merged into the 6.1 branch. Discussion ---------- Minor cleanup | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - I was reviewing #44405 when it was merged. I had some minor fixes to do so I added them to this PR. Commits ------- c68878c Minor cleanup
…enanbr) This PR was merged into the 6.1 branch. Discussion ---------- [Routing] Allow using services in the route condition Documents symfony/symfony#44405 Closes #16714 Commits ------- c2478da [Routing] Allow using services in the route condition
…nditionService] (nicolas-grekas) This PR was merged into the 6.1 branch. Discussion ---------- [FrameworkBundle] Simplify registration of #[AsRoutingConditionService] | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Small simplification on top of #44405 The changes on `composer.json` just bump explicitly what is already bumped transitively. Commits ------- 953f505 [FrameworkBundle] Simplify registration of #[AsRoutingConditionService]