From 0c55acbd1c82dbdee4830e76d2cb16eb8123173f Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 13:21:56 +0100 Subject: [PATCH 1/3] Fixed bug where not the interface DateTimeInterface but only the implementation DateTime was accepted --- src/Symfony/Component/HttpFoundation/Cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 061703d9ca0e8..6392c5243153a 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -51,7 +51,7 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom } // convert expiration time to a Unix timestamp - if ($expire instanceof \DateTime) { + if ($expire instanceof \DateTimeInterface) { $expire = $expire->format('U'); } elseif (!is_numeric($expire)) { $expire = strtotime($expire); From 5b31e67e5d691b9baa0f1f9dc6ad99f29064d83f Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 13:31:27 +0100 Subject: [PATCH 2/3] Added unit test for the DateImmutable variant --- src/Symfony/Component/HttpFoundation/Tests/CookieTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index fd90103e42e3d..d3f5dff181604 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -85,6 +85,14 @@ public function testConstructorWithDateTime() $this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date'); } + public function testConstructorWithDateTimeImmutable() + { + $expire = new \DateTimeImmutable(); + $cookie = new Cookie('foo', 'bar', $expire); + + $this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date'); + } + public function testGetExpiresTimeWithStringValue() { $value = '+1 day'; From 196d8e09c1faad7b87cfc2b7212b7fd7189c7c4d Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 13:38:50 +0100 Subject: [PATCH 3/3] Fixed the documentation for the Cookie constructor --- src/Symfony/Component/HttpFoundation/Cookie.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 6392c5243153a..01ff8990b5e18 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -29,13 +29,13 @@ class Cookie /** * Constructor. * - * @param string $name The name of the cookie - * @param string $value The value of the cookie - * @param int|string|\DateTime $expire The time the cookie expires - * @param string $path The path on the server in which the cookie will be available on - * @param string $domain The domain that the cookie is available to - * @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client - * @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol + * @param string $name The name of the cookie + * @param string $value The value of the cookie + * @param int|string|\DateTimeInterface $expire The time the cookie expires + * @param string $path The path on the server in which the cookie will be available on + * @param string $domain The domain that the cookie is available to + * @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client + * @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol * * @throws \InvalidArgumentException */