If we wish to manipulate a request using middleware before any routing occurs, then this isn't currently possible.
To remedy this, we could either have a pre-routing middleware stack, or you could make the Router implement RequestHandlerInterface, since this method here
public function dispatch(ServerRequestInterface $request): ResponseInterface
is essentially the same as the handle method
public function handle(ServerRequestInterface $request): ResponseInterface
which would allow us to pass the router into another stack.
Personally I prefer the first idea, however it would do no harm whatsoever to also implement the interface, the dispatch method could be @deprecated and call the handle method instead.
I left a comment on this closed issue https://github.com/thephpleague/route/issues/261
If we wish to manipulate a request using middleware before any routing occurs, then this isn't currently possible.
To remedy this, we could either have a pre-routing middleware stack, or you could make the Router implement
RequestHandlerInterface
, since this method herepublic function dispatch(ServerRequestInterface $request): ResponseInterface
is essentially the same as the handle method
public function handle(ServerRequestInterface $request): ResponseInterface
which would allow us to pass the router into another stack.
Personally I prefer the first idea, however it would do no harm whatsoever to also implement the interface, the dispatch method could be
@deprecated
and call the handle method instead.I have sent a pull request for the RequestHandlerInterface approach. https://github.com/thephpleague/route/pull/271
Your thoughts?