Adding optional parameters in Lumen routes

I’ve been working on migrating Ushahidi from Kohana to Lumen recently. Lumen uses a FastRoute instead of Laravels core router. This is faster than the core route, but also more limited.

Initially reading the documentation it appears not to support optional URL parameters. But digging into the Fast Route docs it turns out there is some support:

parts of the route enclosed in [...] are considered optional, so that /foo[bar] will match both /foo and /foobar. Optional parts are only supported in a trailing position, not in the middle of a route.

So you can do something like

$app->get('/config[/{id}]', 'SomeController');

It also turns out that Lumen doesn’t strip trailing slashes when parsing URLs so the optional parameters were a useful workaround. I have a few routes like

$app->get('/config[/]', 'ConfigController@index');