From 624448346964a490dfbd3618475d757377a385fa Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 13:21:56 +0100 Subject: [PATCH 1/6] 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 6c4ba9b4320febd679a95031cddf52d5e945fce6 Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 13:31:27 +0100 Subject: [PATCH 2/6] 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 a9ef5d533604d2de8e28baa1bdf935887d4ac281 Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 13:38:50 +0100 Subject: [PATCH 3/6] 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 */ From 81c8ef2171e6287527ddf65616139eef03a169fc Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 14:34:34 +0100 Subject: [PATCH 4/6] Added the check for DateTimeImmutable in the cookie constructor --- src/Symfony/Component/HttpFoundation/Cookie.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 01ff8990b5e18..3d4aeafa88286 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|\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 + * @param string $name The name of the cookie + * @param string $value The value of the cookie + * @param int|string|\DateTime|\DateTimeImmutable $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 */ @@ -51,7 +51,7 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom } // convert expiration time to a Unix timestamp - if ($expire instanceof \DateTimeInterface) { + if ($expire instanceof \DateTime || $expire instanceof \DateTimeImmutable) { $expire = $expire->format('U'); } elseif (!is_numeric($expire)) { $expire = strtotime($expire); From e74fe0c82384e7cdd313c01741274c1aa0a8bbd7 Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 14:35:35 +0100 Subject: [PATCH 5/6] Added php 5.5 annotation --- src/Symfony/Component/HttpFoundation/Tests/CookieTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index d3f5dff181604..222786533ecca 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -85,6 +85,9 @@ public function testConstructorWithDateTime() $this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date'); } + /** + * @requires PHP 5.5 + */ public function testConstructorWithDateTimeImmutable() { $expire = new \DateTimeImmutable(); From ea84375890a517074b161a451efe9be076424092 Mon Sep 17 00:00:00 2001 From: Wouter de Wild Date: Thu, 14 Jan 2016 14:42:51 +0100 Subject: [PATCH 6/6] Changed immutable implementation reference to the interface reference, DateTimeInterface --- src/Symfony/Component/HttpFoundation/Cookie.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 3d4aeafa88286..13d69f3bd2edd 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -31,7 +31,7 @@ class Cookie * * @param string $name The name of the cookie * @param string $value The value of the cookie - * @param int|string|\DateTime|\DateTimeImmutable $expire The time the cookie expires + * @param int|string|\DateTime|\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 @@ -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 || $expire instanceof \DateTimeImmutable) { + if ($expire instanceof \DateTime || $expire instanceof \DateTimeInterface) { $expire = $expire->format('U'); } elseif (!is_numeric($expire)) { $expire = strtotime($expire);