Skip to content

Commit

Permalink
[HttpFoundation] added a setCache() method to ease setting the HTTP c…
Browse files Browse the repository at this point in the history
…ache headers in one simple call
  • Loading branch information
fabpot committed Nov 12, 2010
1 parent f669674 commit 942104a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -534,6 +534,44 @@ public function setEtag($etag = null, $weak = false)
}
}

/**
* Sets Response cache headers.
*
* Available options are: etag, last_modified, private, and public.
*
* @param array $options An array of cache options
*/
public function setCache(array $options)
{
if ($diff = array_diff_key($options, array('etag', 'last_modified', 'private', 'public'))) {
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_keys($diff))));
}

if (isset($options['etag'])) {
$this->setEtag($options['etag']);
}

if (isset($options['last_modified'])) {
$this->setLastModified($options['last_modified']);
}

if (isset($options['public'])) {
if ($options['public']) {
$this->setPublic();
} else {
$this->setPrivate();
}
}

if (isset($options['private'])) {
if ($options['private']) {
$this->setPrivate();
} else {
$this->setPublic();
}
}
}

/**
* Modifies the response so that it conforms to the rules defined for a 304 status code.
*
Expand Down

0 comments on commit 942104a

Please sign in to comment.