-
Notifications
You must be signed in to change notification settings - Fork 89
add doc for middleware usage in "dispatch" event #94
add doc for middleware usage in "dispatch" event #94
Conversation
@samsonasik Please create a new Thanks! |
@weierophinney done ;). moved to cookbook and updated mkdocs.yml |
$eventManager->attach('dispatch', function ($e) use ($services) { | ||
$request = Psr7ServerRequest::fromZend($e->getRequest()); | ||
$response = Psr7Response::fromZend($e->getResponse()); | ||
$result = ($services->get(AuthorizationMiddleware::class))($request, $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you could pass an empty closure as third parameter to the middleware, so that if the middleware return $next($req, $res)
, then $result will be null
, and if the middleware return $response
, then $result
will be a response. In case it returns a response, you can convert it back to Zend\Http and return it (short-circuiting).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ;)
@samsonasik now in listener, you can add this: if ($result instanceof \Psr\Http\Message\ResponseInterface) {
return Psr7Response::toZend($result);
} So that the middleware becomes able to short-circuit, for example some |
@danizord done ;) Thank you ;) |
add doc for middleware usage in "dispatch" event
Thanks, @samsonasik ! |
#92