Middleware piped may be either callables or service names. Middleware
specified as services will be wrapped in a closure similar to the
following:
function ($error, $request, $response, $next) use ($container, $middleware) {
$invokable = $container->get($middleware);
if (! is_callable($invokable)) {
throw new Exception\InvalidMiddlewareException(sprintf(
'Lazy-loaded middleware "%s" is not invokable',
$middleware
));
}
return $invokable($error, $request, $response, $next);
};
This is done to delay fetching the middleware until it is actually used;
the upshot is that you will not be notified if the service is invalid to
use as middleware until runtime.
Once middleware detection and wrapping (if necessary) is complete,
proxies to pipe().