[HttpFoundation][Cookie] Cookie DateTimeInterface fix
This commit is contained in:
parent
bbbb0796f4
commit
f1f9754bcb
@ -31,7 +31,7 @@ class Cookie
|
|||||||
*
|
*
|
||||||
* @param string $name The name of the cookie
|
* @param string $name The name of the cookie
|
||||||
* @param string $value The value of the cookie
|
* @param string $value The value of the cookie
|
||||||
* @param int|string|\DateTime $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 $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 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 $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
|
||||||
@ -51,7 +51,7 @@ class Cookie
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert expiration time to a Unix timestamp
|
// convert expiration time to a Unix timestamp
|
||||||
if ($expire instanceof \DateTime) {
|
if ($expire instanceof \DateTime || $expire instanceof \DateTimeInterface) {
|
||||||
$expire = $expire->format('U');
|
$expire = $expire->format('U');
|
||||||
} elseif (!is_numeric($expire)) {
|
} elseif (!is_numeric($expire)) {
|
||||||
$expire = strtotime($expire);
|
$expire = strtotime($expire);
|
||||||
|
@ -85,6 +85,17 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 5.5
|
||||||
|
*/
|
||||||
|
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()
|
public function testGetExpiresTimeWithStringValue()
|
||||||
{
|
{
|
||||||
$value = '+1 day';
|
$value = '+1 day';
|
||||||
|
Reference in New Issue
Block a user