Ver Fonte

[HttpKernel] moved getDate() from ParameterBag to HeaderBag

Fabien Potencier há 15 anos atrás
pai
commit
d8752c7fab

+ 21 - 0
src/Symfony/Components/HttpKernel/HeaderBag.php

@@ -121,6 +121,27 @@ class HeaderBag extends ParameterBag
         return $this->cacheControl;
     }
 
+    /**
+     * Returns the HTTP header value converted to a date.
+     *
+     * @param string    $key     The parameter key
+     * @param \DateTime $default The default value
+     *
+     * @return \DateTime The filtered value
+     */
+    public function getDate($key, \DateTime $default = null)
+    {
+        if (null === $value = $this->get($key)) {
+            return $default;
+        }
+
+        if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
+            throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
+        }
+
+        return $date;
+    }
+
     /**
      * Normalizes a HTTP header name.
      *

+ 0 - 13
src/Symfony/Components/HttpKernel/ParameterBag.php

@@ -147,17 +147,4 @@ class ParameterBag
     {
         return (int) $this->get($key, $default);
     }
-
-    public function getDate($key, \DateTime $default = null)
-    {
-        if (null === $value = $this->get($key)) {
-            return $default;
-        }
-
-        if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
-            throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
-        }
-
-        return $date;
-    }
 }