Is there any way of using Type-Hint while defining routes?
So far I’ve found regex which is enough but having something like registering type-hint and using it multiple times would be cleaner.
Looking for something like this:
$app->get('/article/{slug:[A-Za-z]+}', []);
// expectation
$app->get('/article/{slug:slug}', []);
I saw that league/route have this feature which is also built on top of FastRoute.
odan
May 13, 2021, 8:52am
2
I’m not sure what you mean by “type hints” in this context.
Do you eventually mean the pattern matcher for regular expression aliases?
$router->addPatternMatcher('wordStartsWithM', '(m|M)[a-zA-Z]+');
$router->map('GET', 'users/teams/{name:wordStartsWithM}', function ());
Yeah.
I was asking for this.
How to achieve this in slim?
odan
May 13, 2021, 10:21am
4
As far as I know this is not supported directly. But since Slim 4 it’s possible to replace the default router (Fastroute) with other implementations, like the Symfony Router. Technically it should also be possible to replace FastRoute with league/route.
Here is an example:
raziul
May 13, 2021, 11:30am
5
Thanks for your help/suggestion