Psr7Middlewares\Middleware\SaveResponse::__invoke PHP Method

__invoke() public method

Execute the middleware.
public __invoke ( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\RequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface
    public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
    {
        $response = $next($request, $response);
        if ($this->canSave($request, $response)) {
            $path = $this->getFilename($request);
            //if it's gz compressed, append .gz
            if (strtolower($response->getHeaderLine('Content-Encoding')) === 'gzip') {
                $path .= '.gz';
            }
            self::writeStream($response->getBody(), $path);
        }
        return $response;
    }