nathggns/Scaffold

Router should match large to small in terms of segments.

Closed this issue · 6 comments

Currently the router uses the first matched route, which can create issues with something like this.

<?php
$router->all('/:controller/:id');
$router->all('/download/:name/:version', 'download', ['version' => 1]);

If you pass a URL such as /download/project/1 to that, it will match the second route, which is fine, but if you pass '/download/project' to it, it will match the first route, which is problematic if you expect $request->params['version'] to be set.

Maybe you should have to indicate optional parts?

<?php
$router->all('/download/:name/:?version', 'download', ['version' => 1]);

This will add 'optional segments' 82fd1a5

I think it reverses the routes array at some time, so in fact it uses the last matching route.

Am 03.01.2013 um 03:23 schrieb Nathaniel Higgins notifications@github.com:

Currently the router uses the first matched route, which can create issues with something like this.

all('/:controller/:id'); $router->all('/download/:name/:version', 'download', ['version' => 1]); If you pass a URL such as /download/project/1 to that, it will match the second route, which is fine, but if you pass '/download/project' to it, it will match the first route, which is problematic if you expect $request->params['version'] to be set. — Reply to this email directly or view it on GitHub.

Optional segements yet have to be implemented.

Am 03.01.2013 um 03:31 schrieb Nathaniel Higgins notifications@github.com:

Maybe you should have to indicate optional parts?

all('/download/:name/:?version', 'download', ['version' => 1]); — Reply to this email directly or view it on GitHub.

They have been implemented in commit 82fd1a5

Yay!

Am 03.01.2013 um 07:30 schrieb Nathaniel Higgins notifications@github.com:

They have been implemented in commit 82fd1a5


Reply to this email directly or view it on GitHub.