-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX] URL value object #16250
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
Comments
I actually know one project in my company where we have a similar solution for this problem. I think it would be nice to have a more usable Url object. |
I think this is just part of making components compatible with PSR-7. There is a UriInterface as part of PSR-7.
So I think what you mean is that
For 2) it makes sense IMO. For 1) I don't see the real benefit. I would require the Routing component to use a concrete UriInterface implementation. It is a BC break and it doesn't bring much value as people who want to parse the returned url, can just wrap it themselves in a UriInterface implementation.
This is an implementation detail of the UrlGenerator. And it woulnd't be exposed when we switch to an Uri object as well. So that argument is not relevant. |
@iltar what hinders you to use a PSR-7 implementation? There is no need to reimplement this in symfony at this point. |
I want to stay as close to Symfony as possible when it comes to this kind of code or where possible a generic vendor package. If there's a chance it might be in Symfony, I won't create my own code/package for it. |
This is an example of a similar logic
Sorry I missed the UriInterface issue. I was searching for wrong keywords. |
Sometimes you need to parse and modify URL yourself. There is parse_url function in PHP. But it returns all components as array. Rebuilding the URL from the array is a little bit cumbersome because you need lots of checks like here http://stackoverflow.com/questions/4354904/php-parse-url-reverse-parsed-url#answer-31691249
And there is also some hardcoded logic in UrlGenerator like this
https://github.com/symfony/Routing/blob/master/Generator/UrlGenerator.php#L58
So it's hard to build it the same way UrlGenerator does it. OFC one can use the generator for it but it's not usable for URLs which are not routed.
I think it would be nice to move this logic to a new value object so one can use it for creating/modifying URLs. Like this
https://github.com/nette/http/blob/master/src/Http/Url.php
Not only UrlGenerator could use it. For example RedirectResponse is another candidate which could return it instead of a string so one can just for example safely append query parameter to it. I was solving this issue in my custom authentication failure handler which overrides the default symfony one and appends query parameter to the RedirectResponse.
What do you think?
EDIT: Or if it was too big change then at least moving the hardcoded logic from urlgenerator would also be useful. Maybe even just an utility class...
The text was updated successfully, but these errors were encountered: