Moved managing cookies of HeaderBag in ResponseHeaderBag

By example, a cookie can't be set in a request
This commit is contained in:
Francis Besset 2011-07-04 20:46:58 +02:00
parent e8ea852179
commit f08eeb4433
2 changed files with 62 additions and 63 deletions

View File

@ -19,7 +19,6 @@ namespace Symfony\Component\HttpFoundation;
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 @@ class HeaderBag
}
}
/**
* 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.
*

View File

@ -19,6 +19,7 @@ namespace Symfony\Component\HttpFoundation;
class ResponseHeaderBag extends HeaderBag
{
protected $computedCacheControl = array();
protected $cookies = array();
/**
* Constructor.
@ -102,6 +103,67 @@ class ResponseHeaderBag extends HeaderBag
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
*