[RequestHandler] fixed HeaderBag usage

This commit is contained in:
Fabien Potencier 2010-05-03 18:10:24 +02:00
parent bdbb02d7b9
commit 4be3a508f1
2 changed files with 21 additions and 16 deletions

View File

@ -36,14 +36,14 @@ class CacheControl
*/ */
public function __construct(HeaderBag $bag, $header, $type = null) public function __construct(HeaderBag $bag, $header, $type = null)
{ {
$this->bag = $bag;
$this->attributes = $this->parse($header);
if (null !== $type && !in_array($type, array('request', 'response'))) if (null !== $type && !in_array($type, array('request', 'response')))
{ {
throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the CacheControl constructor.', $type)); throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the CacheControl constructor.', $type));
} }
$this->type = $type; $this->type = $type;
$this->bag = $bag;
$this->attributes = $this->parse($header);
} }
public function __toString() public function __toString()

View File

@ -24,12 +24,28 @@ class HeaderBag extends ParameterBag
protected $type; protected $type;
/** /**
* Replaces the current HTTP headers by a new set. * Constructor.
* *
* @param array $parameters An array of HTTP headers * @param array $parameters An array of HTTP headers
* @param string $type The type (null, request, or response) * @param string $type The type (null, request, or response)
*/ */
public function replace(array $parameters = array(), $type = null) public function __construct(array $parameters = array(), $type = null)
{
$this->replace($parameters);
if (null !== $type && !in_array($type, array('request', 'response')))
{
throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the HeaderBag constructor.', $type));
}
$this->type = $type;
}
/**
* Replaces the current HTTP headers by a new set.
*
* @param array $parameters An array of HTTP headers
*/
public function replace(array $parameters = array())
{ {
$this->cacheControl = null; $this->cacheControl = null;
$this->parameters = array(); $this->parameters = array();
@ -37,12 +53,6 @@ class HeaderBag extends ParameterBag
{ {
$this->parameters[strtr(strtolower($key), '_', '-')] = $value; $this->parameters[strtr(strtolower($key), '_', '-')] = $value;
} }
if (null !== $type && !in_array($type, array('request', 'response')))
{
throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the HeaderBag constructor.', $type));
}
$this->type = $type;
} }
/** /**
@ -76,11 +86,6 @@ class HeaderBag extends ParameterBag
} }
$this->parameters[$key] = $value; $this->parameters[$key] = $value;
if ('cache-control' == $key)
{
$this->cacheControl = null;
}
} }
/** /**