route
route copied to clipboard
Feature request: Treat Route `$handler` that implements RequestHandlerInterface as callable
We have an implementation of RequestHandlerInterface for every route in our app. We currently have to register them on the router like this (simplified for example):
$helloRequestHandler = new HelloRequestHandler(); // implements RequestHandlerInterface
$router = new Router();
$router->get('/hello', [$helloRequestHandler, 'handle']);
Since RequestHandlerInterface is an interface from PSR-15, and this package supports PSR-15 (middlewares), it would be cool if the router could automatically detect the 'handle' method on the request handlers, so we could just register them like:
$helloRequestHandler = new HelloRequestHandler(); // implements RequestHandlerInterface
$router = new Router();
$router->get('/hello', $helloRequestHandler);
(Or when injecting a dependency container into the router, as a FQN / service name without the ::handle
)
Is this something that you would consider approving if I created a PR for this?