You are here

public function Response::setCache in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Response.php \Symfony\Component\HttpFoundation\Response::setCache()

Sets the response's cache headers (validation and/or expiration).

Available options are: etag, last_modified, max_age, s_maxage, private, and public.

Parameters

array $options An array of cache options:

Return value

Response

Throws

\InvalidArgumentException

File

vendor/symfony/http-foundation/Response.php, line 878

Class

Response
Response represents an HTTP response.

Namespace

Symfony\Component\HttpFoundation

Code

public function setCache(array $options) {
  if ($diff = array_diff(array_keys($options), array(
    'etag',
    'last_modified',
    'max_age',
    's_maxage',
    'private',
    'public',
  ))) {
    throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
  }
  if (isset($options['etag'])) {
    $this
      ->setEtag($options['etag']);
  }
  if (isset($options['last_modified'])) {
    $this
      ->setLastModified($options['last_modified']);
  }
  if (isset($options['max_age'])) {
    $this
      ->setMaxAge($options['max_age']);
  }
  if (isset($options['s_maxage'])) {
    $this
      ->setSharedMaxAge($options['s_maxage']);
  }
  if (isset($options['public'])) {
    if ($options['public']) {
      $this
        ->setPublic();
    }
    else {
      $this
        ->setPrivate();
    }
  }
  if (isset($options['private'])) {
    if ($options['private']) {
      $this
        ->setPrivate();
    }
    else {
      $this
        ->setPublic();
    }
  }
  return $this;
}