In version 3, middleware accepts 3 arguments:
\Psr\Http\Message\ServerRequestInterface- The PSR7 request object
\Psr\Http\Message\ResponseInterface- The PSR7 response object
callable- The next middleware callable
In version 4 middleware has
Psr\Http\Message\ServerRequestInterface- The PSR-7 request object
Psr\Http\Server\RequestHandlerInterface- The PSR-15 request handler object
This is confusing to me because, while authenticating for example, if the user isn’t authorized I want to return a response without calling the handler. Do I need to create a new Response, if so how do I do that?
Edit: I figured it out, you create a new response with
$response = $app->getResponseFactory()->createResponse();
It was a bit hard to find, it isn’t mentioned anywhere, I just saw it being used in Custom Error Handlers part of the guide.