Skip to content

Commit 65d6c9e

Browse files
author
Peter Bouwdewijn
committed
Fix #67 Pass cookie parts as intended to cookie object.
Use datetime cookie constant.
1 parent bda9fa0 commit 65d6c9e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

spec/CookiePluginSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function it_saves_cookie(RequestInterface $request, ResponseInterface $response,
150150
'cookie=value; expires=%s; Max-Age=60; path=/; domain=test.com; secure; HttpOnly',
151151
(new \DateTime())->add(
152152
new \DateInterval('PT60S')
153-
)->format(DATE_COOKIE)
153+
)->format(\DateTime::COOKIE)
154154
)
155155
]);
156156

src/CookiePlugin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ private function createCookie(RequestInterface $request, $setCookie)
9797

9898
list($name, $cookieValue) = $this->createValueKey(array_shift($parts));
9999

100-
$expires = 0;
100+
$maxAge = null;
101+
$expires = null;
101102
$domain = $request->getUri()->getHost();
102103
$path = $request->getUri()->getPath();
103104
$secure = false;
@@ -109,12 +110,11 @@ private function createCookie(RequestInterface $request, $setCookie)
109110

110111
switch (strtolower($key)) {
111112
case 'expires':
112-
$expires = \DateTime::createFromFormat(DATE_COOKIE, $value)->getTimestamp()
113-
- (new \DateTime())->getTimestamp();
113+
$expires = \DateTime::createFromFormat(\DateTime::COOKIE, $value);
114114
break;
115115

116116
case 'max-age':
117-
$expires = (int) $value;
117+
$maxAge = (int) $value;
118118
break;
119119

120120
case 'domain':
@@ -135,7 +135,7 @@ private function createCookie(RequestInterface $request, $setCookie)
135135
}
136136
}
137137

138-
return new Cookie($name, $cookieValue, $expires, $domain, $path, $secure, $httpOnly);
138+
return new Cookie($name, $cookieValue, $maxAge, $domain, $path, $secure, $httpOnly, $expires);
139139
}
140140

141141
/**

0 commit comments

Comments
 (0)