diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index fb3c3aaf368d..42097fe78781 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -19,7 +19,6 @@ class HeaderBag { protected $headers; - protected $cookies; protected $cacheControl; /** @@ -30,7 +29,6 @@ class HeaderBag public function __construct(array $headers = array()) { $this->cacheControl = array(); - $this->cookies = array(); $this->headers = array(); foreach ($headers as $key => $values) { $this->set($key, $values); @@ -200,67 +198,6 @@ public function remove($key) } } - /** - * Sets a cookie. - * - * @param Cookie $cookie - * @return void - */ - public function setCookie(Cookie $cookie) - { - $this->cookies[$cookie->getName()] = $cookie; - } - - /** - * Removes a cookie from the array, but does not unset it in the browser - * - * @param string $name - * @return void - */ - public function removeCookie($name) - { - unset($this->cookies[$name]); - } - - /** - * Whether the array contains any cookie with this name - * - * @param string $name - * @return Boolean - */ - public function hasCookie($name) - { - return isset($this->cookies[$name]); - } - - /** - * Returns a cookie - * - * @param string $name - * - * @throws \InvalidArgumentException When the cookie does not exist - * - * @return Cookie - */ - public function getCookie($name) - { - if (!$this->hasCookie($name)) { - throw new \InvalidArgumentException(sprintf('There is no cookie with name "%s".', $name)); - } - - return $this->cookies[$name]; - } - - /** - * Returns an array with all cookies - * - * @return array - */ - public function getCookies() - { - return $this->cookies; - } - /** * Returns the HTTP header value converted to a date. * diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 5f6d408646e1..7e7de11eef55 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -19,6 +19,7 @@ class ResponseHeaderBag extends HeaderBag { protected $computedCacheControl = array(); + protected $cookies = array(); /** * Constructor. @@ -102,6 +103,67 @@ public function getCacheControlDirective($key) return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null; } + /** + * Sets a cookie. + * + * @param Cookie $cookie + * @return void + */ + public function setCookie(Cookie $cookie) + { + $this->cookies[$cookie->getName()] = $cookie; + } + + /** + * Removes a cookie from the array, but does not unset it in the browser + * + * @param string $name + * @return void + */ + public function removeCookie($name) + { + unset($this->cookies[$name]); + } + + /** + * Whether the array contains any cookie with this name + * + * @param string $name + * @return Boolean + */ + public function hasCookie($name) + { + return isset($this->cookies[$name]); + } + + /** + * Returns a cookie + * + * @param string $name + * + * @throws \InvalidArgumentException When the cookie does not exist + * + * @return Cookie + */ + public function getCookie($name) + { + if (!$this->hasCookie($name)) { + throw new \InvalidArgumentException(sprintf('There is no cookie with name "%s".', $name)); + } + + return $this->cookies[$name]; + } + + /** + * Returns an array with all cookies + * + * @return array + */ + public function getCookies() + { + return $this->cookies; + } + /** * Clears a cookie in the browser *