hoaproject / Router

The Hoa\Router library.
https://hoa-project.net/
28 stars 11 forks source link

Append unused variables to the querystring when unrouting rules #33

Closed K-Phoen closed 9 years ago

K-Phoen commented 9 years ago

To keep it short, this goal of this PR is to mimic Symfony's routing component behaviour regarding routes generation.

As explained in their documentation, when generating a URL from a route extra parameters are added to the URI as query string.

Hywan commented 9 years ago

Smart. Great PR! How to deal with arrays? What if we append an array? We should build query strings like foo[]=…&foo[]=…. Does it work?

Hywan commented 9 years ago

@K-Phoen That's a good idea but I was thinking: What if we change the route and an undefined variable is now a defined one. Is it dangerous? What is the impact of such a modification? /cc @osaris

K-Phoen commented 9 years ago

I didn't test but I think that query strings like foo[]=…&foo[]=… should work as http_build_query is supposed to handle multi-dimensional arrays.

For your second concern, I don't think that the impact is dangerous as the previously undefined variable will disappear from the query string to be embedded directly in the URL.

This would look like this: /blog/posts?page=1 becomes /blog/posts/page/1.

Hywan commented 9 years ago

@K-Phoen Correct.

Well, sounds excellent for me! Waiting for the review of @osaris :smiley:.

osaris commented 9 years ago

The behaviour for variables becoming defined/undefined is what I expected and it make sense from user (of the lib) point of view. The patch is good to merge from my point of view ! Thanks @K-Phoen

Hywan commented 9 years ago

@osaris :+1: