Zend\Expressive\Application::dispatchMiddleware PHP Method

dispatchMiddleware() public method

If the request does not have the route result, calls on the next middleware. Next, it checks if the route result has matched middleware; if not, it raises an exception. Finally, it attempts to marshal the middleware, and dispatches it when complete, return the response.
public dispatchMiddleware ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next )
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
    public function dispatchMiddleware(ServerRequestInterface $request, ResponseInterface $response, callable $next)
    {
        $routeResult = $request->getAttribute(Router\RouteResult::class, false);
        if (!$routeResult) {
            return $next($request, $response);
        }
        $middleware = $routeResult->getMatchedMiddleware();
        if (!$middleware) {
            throw new Exception\InvalidMiddlewareException(sprintf('The route %s does not have a middleware to dispatch', $routeResult->getMatchedRouteName()));
        }
        $middleware = $this->prepareMiddleware($middleware, $this->container);
        return $middleware($request, $response, $next);
    }