Zend\Expressive\MarshalMiddlewareTrait::prepareMiddleware PHP Метод

prepareMiddleware() приватный Метод

Performs a number of checks on $middleware to prepare it for piping to the application: - If it's callable, it's returned immediately. - If it's a non-callable array, it's passed to marshalMiddlewarePipe(). - If it's a string service name, it's passed to marshalLazyMiddlewareService(). - If it's a string class name, it's passed to marshalInvokableMiddleware(). - If no callable is created, an exception is thrown.
private prepareMiddleware ( mixed $middleware, Interop\Container\ContainerInterface $container = null, boolean $forError = false ) : callable
$middleware mixed
$container Interop\Container\ContainerInterface
$forError boolean Whether or not generated middleware is intended to represent error middleware; defaults to false.
Результат callable
    private function prepareMiddleware($middleware, ContainerInterface $container = null, $forError = false)
    {
        if (is_callable($middleware)) {
            return $middleware;
        }
        if (is_array($middleware)) {
            return $this->marshalMiddlewarePipe($middleware, $container, $forError);
        }
        if (is_string($middleware) && $container && $container->has($middleware)) {
            $method = $forError ? 'marshalLazyErrorMiddlewareService' : 'marshalLazyMiddlewareService';
            return $this->{$method}($middleware, $container);
        }
        $callable = $middleware;
        if (is_string($middleware)) {
            $callable = $this->marshalInvokableMiddleware($middleware);
        }
        if (!is_callable($callable)) {
            throw new Exception\InvalidMiddlewareException(sprintf('Unable to resolve middleware "%s" to a callable', is_object($middleware) ? get_class($middleware) . "[Object]" : gettype($middleware) . '[Scalar]'));
        }
        return $callable;
    }