Psr7Middlewares\Middleware\ReadResponse::__invoke PHP Метод

__invoke() публичный Метод

Execute the middleware.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
Результат Psr\Http\Message\ResponseInterface
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
    {
        //If the method is not allowed
        if ($request->getMethod() !== 'GET') {
            if ($this->continueOnError) {
                return $next($request, $response);
            }
            return $response->withStatus(405);
        }
        $file = $this->getFilename($request);
        //If the file does not exists, check if is gzipped
        if (!is_file($file)) {
            $file .= '.gz';
            if (EncodingNegotiator::getEncoding($request) !== 'gzip' || !is_file($file)) {
                if ($this->continueOnError) {
                    return $next($request, $response);
                }
                return $response->withStatus(404);
            }
            $response = $response->withHeader('Content-Encoding', 'gzip');
        }
        //Handle range header
        return $this->range($request, $response->withBody(self::createStream($file, 'r')));
    }