Skip to content

Commit

Permalink
[RequestHandler] fixed HeaderBag usage
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 3, 2010
1 parent bdbb02d commit 4be3a50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Components/RequestHandler/CacheControl.php
Expand Up @@ -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()
Expand Down
31 changes: 18 additions & 13 deletions src/Symfony/Components/RequestHandler/HeaderBag.php
Expand Up @@ -24,19 +24,14 @@ 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->cacheControl = null;
$this->parameters = array();
foreach ($parameters as $key => $value)
{
$this->parameters[strtr(strtolower($key), '_', '-')] = $value;
}
$this->replace($parameters);

if (null !== $type && !in_array($type, array('request', 'response')))
{
Expand All @@ -45,6 +40,21 @@ public function replace(array $parameters = array(), $type = null)
$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();
foreach ($parameters as $key => $value)
{
$this->parameters[strtr(strtolower($key), '_', '-')] = $value;
}
}

/**
* Returns a header value by name.
*
Expand Down Expand Up @@ -76,11 +86,6 @@ public function set($key, $value, $replace = true)
}

$this->parameters[$key] = $value;

if ('cache-control' == $key)
{
$this->cacheControl = null;
}
}

/**
Expand Down

0 comments on commit 4be3a50

Please sign in to comment.