From 4be3a508f1af08f8c20a25f5aeaa817a339c386c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 May 2010 18:10:24 +0200 Subject: [PATCH] [RequestHandler] fixed HeaderBag usage --- .../RequestHandler/CacheControl.php | 6 ++-- .../Components/RequestHandler/HeaderBag.php | 31 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Components/RequestHandler/CacheControl.php b/src/Symfony/Components/RequestHandler/CacheControl.php index 7b168ef253..ce89294844 100644 --- a/src/Symfony/Components/RequestHandler/CacheControl.php +++ b/src/Symfony/Components/RequestHandler/CacheControl.php @@ -36,14 +36,14 @@ class CacheControl */ 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'))) { throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the CacheControl constructor.', $type)); } $this->type = $type; + + $this->bag = $bag; + $this->attributes = $this->parse($header); } public function __toString() diff --git a/src/Symfony/Components/RequestHandler/HeaderBag.php b/src/Symfony/Components/RequestHandler/HeaderBag.php index d22749951c..2415a6c457 100644 --- a/src/Symfony/Components/RequestHandler/HeaderBag.php +++ b/src/Symfony/Components/RequestHandler/HeaderBag.php @@ -24,12 +24,28 @@ class HeaderBag extends ParameterBag protected $type; /** - * Replaces the current HTTP headers by a new set. + * Constructor. * * @param array $parameters An array of HTTP headers * @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->parameters = array(); @@ -37,12 +53,6 @@ class HeaderBag extends ParameterBag { $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; - - if ('cache-control' == $key) - { - $this->cacheControl = null; - } } /**