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

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

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
Результат Psr\Http\Message\ResponseInterface
    public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
    {
        $response = $next($request, $response);
        $cacheControl = $response->getHeaderLine('Cache-Control') ?: '';
        if (stripos($cacheControl, 'max-age') === false) {
            $mime = Utils\Helpers::getMimeType($response);
            $expires = new DateTimeImmutable(isset($this->expires[$mime]) ? $this->expires[$mime] : $this->expiresDefault);
            $cacheControl .= ' max-age=' . ($expires->getTimestamp() - time());
            return $response->withHeader('Cache-Control', trim($cacheControl))->withHeader('Expires', $expires->format('D, d M Y H:i:s') . ' GMT');
        }
        return $response;
    }