-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] extra parameters objects should be casted to string #26992
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 don't think this is something you want. If an object has a If you want this particular feature, please check out: https://github.com/iltar/http-bundle |
@iltar it looks like your bundle serves a different purpose. Thanks for your suggestion anyway |
I transforms an object to it's (string) representation, but with configuration rather than convention. |
Maybe you missed the point when I explain I need this for extra route parameters |
That will just work, all the bundle does, is convert objects to scalar values, regardless of what's defined in the Route definition. I haven't configured it in a while, because most cases are entities for me where the PK is used, but this should work iltar_http:
router:
mapped_properties:
Ramsey\Uuid: __toString /** @Route("/", name="index") */
$urlGenerator->generate('index', ['foo' => $uuid]);
#Should generate: ?foo=7ecff38e-4145-11e8-80b9-0242ac140004 If this is not the case, I should probably fix this. When I have time, I'll add a test to verify this behavior. Edit: I've seen this feature request come by quite often. If desired, I can also try to incorporate it into Symfony, or anyone can for that matter. |
@linaori do you have time to implement this ? |
I can help if needed, don't have time to work on this myself. Any desired code can be grabbed from https://github.com/linaori/http-bundle and used. When implemented, I can deprecate this package and refer to symfony |
Thank you for this suggestion. |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
Issue still stands |
It's not a duplicate.
It's working if route is something like |
Closing as explained in the related PR. |
…in route (garak) This PR was merged into the 4.4 branch. Discussion ---------- [Routing] add a warning about object as extra parameter in route As explained in [this issue](symfony/symfony#26992), objects are not converted to string when used as extra parameter. I think that user should be warned about such behaviour, because failing to casting object is resulting in an empty query string, without any notice/warning/error. Commits ------- 070c9bb add a warning about object as extra parameter in route
… strings with stringables (nicolas-grekas, OskarStark) This PR was merged into the 5.4 branch. Discussion ---------- [BrowserKit][HttpClient][Routing] support building query strings with stringables | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes (minor) | Deprecations? | no | Tickets | Fix #26992 | License | MIT | Doc PR | - Allows using eg an instance of `Uid` as a route parameter. Replaces #42057 Commits ------- 65e2cac Add check and tests for public properties ab38bb8 [BrowserKit][HttpClient][Routing] support building query strings with stringables
Real case scenario: I want to pass an extra parameter to a route (see docs), and the value of such parameter is an object. The typical example is a
Uuid
object (e.g. Ramsey\Uuid).Problem is that PHP is not smart enough and it does not cast objects to string. See related bug on php.net.
Of couse, such feature could be easily obtained in a typical plain PHP context, since it's very easy to cast your object to a string.
In a typical Symfony context, instead, you can't easily cast strings, unless doing ugly things.
Example of not working code:
Example of working code, with ugly workaround:
My proposal is: inside
doGenerate
method ofUrlGenerator
class, Symfony should cast parameters to string before passing them tohttp_build_query
The text was updated successfully, but these errors were encountered: