-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] UrlHelper is now aware of RequestContext changes #50309
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
[HttpFoundation] UrlHelper is now aware of RequestContext changes #50309
Conversation
NOTE: this PR introduce a BC on the constructor of UrlHelper, but since it's final maybe is not required to keep backward compatility. A final constructor is not an internal one. You can still write code than instantiate the class, and would be impacted by the BC break. Constructors are not only called as |
445807a
to
2624c79
Compare
Thank you for the feedback.
Yes, I'm very well aware, I meant that I didn't know if you care of BC of a final helper class. Since you do, I've implemented the compatibility with the deprecation and all. |
2624c79
to
59438c4
Compare
https://symfony.com/bc has a good overview of the Symfony BC policy, including what kind of changes you are allowed to do as a contributor. |
59438c4
to
a016392
Compare
a016392
to
75eb469
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.
(I updated the patch to make it suitable for 5.4)
Thank you @giosh94mhz. |
…changes (giosh94mhz) This PR was merged into the 5.4 branch. Discussion ---------- [HttpFoundation] UrlHelper is now aware of RequestContext changes | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | yes | Tickets | | License | MIT | Doc PR | `RequestContext` in routing can change at runtime after the `UrlHelper` has been created, so using a `RequestContextAwareInterface` instance (i.e. the router) will workaround URL generation issues. In my application I have a CLI command that dynamically create the RequestContext, based on database queries and other user-driven configuration. With this information at hand, I retrieve the router and set the new context that should then be used on any other URL generation. This works for the Router, but then I render some twig templates (to send formatted email) and found that the `UrlHelper` is using the old context, and not helping at all :) Also, the helper is final and without interface, so I have no way of decorating or replacing it. Long story short: in my opinion, the `RequestContext` should be treated just like the `Request`, and so we should use `RequestContextAwareInterface` just like we use the `RequestStack`. ....or maybe the context should be carried out with the `RequestStack`? Any other ideas? ~~no longer relevant: this PR introduce a BC on the constructor of `UrlHelper`, but since it's final maybe is not required to keep backward compatility. If not, I may update the class to support both `RequestContextAwareInterface` and `RequestContext` as the second parameter.~~ Commits ------- a016392 UrlHelper is now aware of RequestContext changes
Thank to you guys, for all your hard work! |
RequestContext
in routing can change at runtime after theUrlHelper
has been created, so using aRequestContextAwareInterface
instance (i.e. the router) will workaround URL generation issues.In my application I have a CLI command that dynamically create the RequestContext, based on database queries and other user-driven configuration. With this information at hand, I retrieve the router and set the new context that should then be used on any other URL generation.
This works for the Router, but then I render some twig templates (to send formatted email) and found that the
UrlHelper
is using the old context, and not helping at all :) Also, the helper is final and without interface, so I have no way of decorating or replacing it.Long story short: in my opinion, the
RequestContext
should be treated just like theRequest
, and so we should useRequestContextAwareInterface
just like we use theRequestStack
.....or maybe the context should be carried out with the
RequestStack
? Any other ideas?no longer relevant: this PR introduce a BC on the constructor ofUrlHelper
, but since it's final maybe is not required to keep backward compatility. If not, I may update the class to support bothRequestContextAwareInterface
andRequestContext
as the second parameter.