Zend\Stratigility\Dispatch::__invoke PHP Method

__invoke() public method

Given a route (which contains the handler for given middleware), the $err value passed to $next, $next, and the request and response objects, dispatch a middleware handler. If $err is non-falsy, and the current handler has an arity of 4, it will be dispatched. If $err is falsy, and the current handler has an arity of < 4, it will be dispatched. In all other cases, the handler will be ignored, and $next will be invoked with the current $err value. If an exception is raised when executing the handler, the exception will be assigned as the value of $err, and $next will be invoked with it.
public __invoke ( Route $route, mixed $err, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$route Route
$err mixed
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface
    public function __invoke(Route $route, $err, ServerRequestInterface $request, ResponseInterface $response, callable $next)
    {
        if (!$this->responsePrototype) {
            $this->setResponsePrototype($response);
        }
        if ($route->handler instanceof ServerMiddlewareInterface) {
            return $this->dispatchInteropMiddleware($route->handler, $next, $request);
        }
        return $this->dispatchCallableMiddleware($route->handler, $next, $request, $response, $err);
    }