route icon indicating copy to clipboard operation
route copied to clipboard

Feature request: Treat Route `$handler` that implements RequestHandlerInterface as callable

Open bertramakers opened this issue 2 years ago • 0 comments

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?

bertramakers avatar Aug 22 '22 12:08 bertramakers