I have an idea about RequestResponseArgs handle strategy in Slim 4, it should be nice, if this strategy cast data types of args right. Like if I have method($request, $response, int $id, string $value), then this strategy cast first arg as int, second arg as string, if no data type is provided, then cast is as string.
@bednic you can create your own strategy and set it on the RouteCollector to be the default strategy for when you add routes.
$app = AppFactory::create();
$strategy = new MyCustomRouteInvocationStrategy();
// Do it for all routes
$routeCollector = $app->getRouteCollector();
$routeCollector->setDefaultRouteInvocationStrategy($strategy);
// Do it for one route only
$app->get('/', function (...) {...})->setInvocationStrategy($strategy);
Yea I know, I can. It was just idea to enchant your strategy to make it more sexy. It doesn't mean it's bug or something. I'm just curious if you are even interested in this improvement and then if you approve this idea I can make some MR later.
I'm not opposed to an improvement as long as it doesn't break the existing functionality. I suppose you'd have to do the parameter detection through reflection and there's going to be a lot of edge cases.. Definitely open to a PR if you want!
Just to give my 2 cents, PHP-DI bridge does this thanks to his Invoker : https://github.com/PHP-DI/Slim-Bridge/blob/master/src/ControllerInvoker.php
It's true, I used to use it in previous version of Slim. I didn't expect it will work with Slim 4, don't know why 馃え. But there is one tricky case with optional parameters. But I suppose it fits my requirement. I will try setup my skeleton with that.
Again, feel free to PR this so we can add it to the library of route invocation strategies. I have no problems with it, it's never going to be the default strategy though.
Slim-Bridge is adding support for Slim 4. I'm closing this as resolved.
Most helpful comment
Slim-Bridge is adding support for Slim 4. I'm closing this as resolved.
See https://github.com/PHP-DI/Slim-Bridge/pull/47