Prechádzať zdrojové kódy

[HttpFoundation] fixed expiration time for Cookie (PHP wants a Unix timestamp)

Fabien Potencier 14 rokov pred
rodič
commit
e2c9fdf2c7

+ 9 - 3
src/Symfony/Component/HttpFoundation/Cookie.php

@@ -41,9 +41,15 @@ class Cookie
             throw new \InvalidArgumentException('The cookie name cannot be empty');
         }
 
-        // check if the expiration is valid
-        if (!$expire instanceof \DateTime && !is_numeric($expire) && (strtotime($expire) === false || strtotime($expire) === -1)) {
-            throw new \InvalidArgumentException('The cookie expiration is not valid');
+        // convert expiration time to a Unix timestamp
+        if ($expire instanceof \DateTime) {
+            $expire = $expire->format('U');
+        } elseif (!is_numeric($expire)) {
+            $expire = strtotime($expire);
+
+            if (false === $expire || -1 === $expire) {
+                throw new \InvalidArgumentException('The cookie expiration time is not valid.');
+            }
         }
 
         $this->name = $name;