Forráskód Böngészése

[RequestHandler] fixed HeaderBag usage

Fabien Potencier 15 éve
szülő
commit
4be3a508f1

+ 3 - 3
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()

+ 18 - 13
src/Symfony/Components/RequestHandler/HeaderBag.php

@@ -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')))
     {
@@ -45,6 +40,21 @@ class HeaderBag extends ParameterBag
     $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.
    *
@@ -76,11 +86,6 @@ class HeaderBag extends ParameterBag
     }
 
     $this->parameters[$key] = $value;
-
-    if ('cache-control' == $key)
-    {
-      $this->cacheControl = null;
-    }
   }
 
   /**