Moved managing cookies of HeaderBag in ResponseHeaderBag
By example, a cookie can't be set in a request
This commit is contained in:
parent
e8ea852179
commit
f08eeb4433
@ -19,7 +19,6 @@ namespace Symfony\Component\HttpFoundation;
|
|||||||
class HeaderBag
|
class HeaderBag
|
||||||
{
|
{
|
||||||
protected $headers;
|
protected $headers;
|
||||||
protected $cookies;
|
|
||||||
protected $cacheControl;
|
protected $cacheControl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,7 +29,6 @@ class HeaderBag
|
|||||||
public function __construct(array $headers = array())
|
public function __construct(array $headers = array())
|
||||||
{
|
{
|
||||||
$this->cacheControl = array();
|
$this->cacheControl = array();
|
||||||
$this->cookies = array();
|
|
||||||
$this->headers = array();
|
$this->headers = array();
|
||||||
foreach ($headers as $key => $values) {
|
foreach ($headers as $key => $values) {
|
||||||
$this->set($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.
|
* Returns the HTTP header value converted to a date.
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,7 @@ namespace Symfony\Component\HttpFoundation;
|
|||||||
class ResponseHeaderBag extends HeaderBag
|
class ResponseHeaderBag extends HeaderBag
|
||||||
{
|
{
|
||||||
protected $computedCacheControl = array();
|
protected $computedCacheControl = array();
|
||||||
|
protected $cookies = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -102,6 +103,67 @@ class ResponseHeaderBag extends HeaderBag
|
|||||||
return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
|
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
|
* Clears a cookie in the browser
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user