Skip to content

upgrade hansott/psr-cookies from 2.0 to 3.0 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": "^7.4",
"ext-session": "^7.4",
"hansott/psr7-cookies": "^2.0.2",
"hansott/psr7-cookies": "^3.0.2",
"psr/http-message": "^1.0.1",
"react/cache": "^1.1.1",
"react/http": "^1.2",
Expand Down
26 changes: 12 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace WyriHaximus\React\Http\Middleware;

use HansOtt\PSR7Cookies\RequestCookies;
use HansOtt\PSR7Cookies\SetCookie;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -39,7 +38,7 @@ final class SessionMiddleware
private SessionIdInterface $sessionId;

/**
* @param array<int, mixed> $cookieParams
* @param array<int, mixed> $cookieParams
*/
public function __construct(
string $cookieName,
Expand Down Expand Up @@ -79,14 +78,14 @@ public function __invoke(ServerRequestInterface $request, callable $next): Promi
private function fetchSessionFromRequest(ServerRequestInterface $request): PromiseInterface
{
$id = '';
$cookies = RequestCookies::createFromRequest($request);
$cookies = $request->getCookieParams();

try {
if (! $cookies->has($this->cookieName)) {
if (! array_key_exists($this->cookieName, $cookies)) {
return resolve(new Session($id, [], $this->sessionId));
}

$id = $cookies->get($this->cookieName)->getValue();
$id = $cookies[$this->cookieName];

return $this->fetchSessionDataFromCache($id)->then(
fn (array $sessionData): Session => new Session($id, $sessionData, $this->sessionId)
Expand Down
24 changes: 12 additions & 12 deletions tests/SessionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static function (): array {
10,
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
],
];
},
Expand All @@ -62,7 +62,7 @@ static function (): array {
'/example/',
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
],
];
Expand All @@ -78,7 +78,7 @@ static function (): array {
'www.example.com',
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
'domain=www.example.com',
],
Expand All @@ -96,7 +96,7 @@ static function (): array {
true,
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
'domain=www.example.com',
'secure',
Expand All @@ -115,7 +115,7 @@ static function (): array {
false,
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
'domain=www.example.com',
],
Expand All @@ -134,7 +134,7 @@ static function (): array {
true,
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
'domain=www.example.com',
'secure',
Expand All @@ -155,7 +155,7 @@ static function (): array {
false,
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
'domain=www.example.com',
],
Expand All @@ -174,7 +174,7 @@ static function (): array {
true,
],
[
'expires=' . gmdate('D, d-M-Y H:i:s T', time() + 10),
'expires=' . gmdate('D, d M Y H:i:s T', time() + 10),
'path=/example/',
'domain=www.example.com',
'httponly',
Expand Down Expand Up @@ -206,7 +206,7 @@ static function (): array {
$t,
sprintf(
'; expires=%s',
gmdate('D, d-M-Y H:i:s T', time() + $t)
gmdate('D, d M Y H:i:s T', time() + $t)
),
];
},
Expand All @@ -220,7 +220,7 @@ static function (): array {
$t,
sprintf(
'; expires=%s',
gmdate('D, d-M-Y H:i:s T', time() + $t)
gmdate('D, d M Y H:i:s T', time() + $t)
),
];
},
Expand All @@ -234,7 +234,7 @@ static function (): array {
$t,
sprintf(
'; expires=%s',
gmdate('D, d-M-Y H:i:s T', time() + $t)
gmdate('D, d M Y H:i:s T', time() + $t)
),
];
},
Expand Down Expand Up @@ -407,7 +407,7 @@ public function testSessionExistsAndEndingIt(): void

self::assertCount(0, $this->cache->getData());
self::assertFalse($session->isActive());
self::assertSame($cookieName . '=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT', $response->getHeaderLine('Set-Cookie'));
self::assertSame($cookieName . '=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT', $response->getHeaderLine('Set-Cookie'));
}

public function testUpdateCacheDeletesOldIds(): void
Expand Down