Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 372f77e

Browse files
committed
Merge branch 'hotfix/21' into develop
Forward port #21 Conflicts: CHANGELOG.md
2 parents 7f6b0a4 + 1c56671 commit 372f77e

4 files changed

+40
-8
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file, in reverse
2424

2525
- Nothing.
2626

27-
## 1.1.1 - TBD
27+
## 1.1.1 - 2018-05-14
2828

2929
### Added
3030

@@ -44,7 +44,10 @@ All notable changes to this project will be documented in this file, in reverse
4444

4545
### Fixed
4646

47-
- Nothing.
47+
- [#21](https://github.com/zendframework/zend-expressive-session-ext/pull/21) fixes a situation whereby during persistence, if no identifier existed for
48+
the session, it was not persisted. Such situations would occur when a new session was created, as
49+
no identifier would yet exist. It now properly generates an identifier and persists the data in
50+
such cirumstances.
4851

4952
## 1.1.0 - 2018-05-10
5053

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017, Zend Technologies USA, Inc.
1+
Copyright (c) 2017-2018, Zend Technologies USA, Inc.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification,

src/PhpSessionPersistence.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-session-ext for the canonical source repository
4-
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2017-2018 Zend Technologies USA Inc. (http://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-session-ext/blob/master/LICENSE.md New BSD License
66
*/
77

88
namespace Zend\Expressive\Session\Ext;
99

10-
use Dflydev\FigCookies\FigCookies\Cookie;
1110
use Dflydev\FigCookies\FigRequestCookies;
1211
use Dflydev\FigCookies\FigResponseCookies;
1312
use Dflydev\FigCookies\SetCookie;
@@ -100,7 +99,11 @@ public function initializeSessionFromRequest(ServerRequestInterface $request) :
10099

101100
public function persistSession(SessionInterface $session, ResponseInterface $response) : ResponseInterface
102101
{
103-
if ($session->isRegenerated()) {
102+
// Regenerate if the session is marked as regenerated
103+
// Regenerate if there is no cookie id set but the session has changed (new session with data)
104+
if ($session->isRegenerated()
105+
|| (! $this->cookie && $session->hasChanged())
106+
) {
104107
$this->regenerateSession();
105108
}
106109

test/PhpSessionPersistenceTest.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-session-ext for the canonical source repository
4-
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2017-2018 Zend Technologies USA Inc. (http://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-session-ext/blob/master/LICENSE.md New BSD License
66
*/
77

@@ -182,7 +182,7 @@ public function testPersistSessionIfSessionHasContents()
182182
{
183183
$this->startSession();
184184
$session = new Session(['foo' => 'bar']);
185-
$this->persistence->persistSession($session, new Response);
185+
$this->persistence->persistSession($session, new Response());
186186
$this->assertSame($session->toArray(), $_SESSION);
187187
}
188188

@@ -416,4 +416,30 @@ public function testPersistSessionReturnsExpectedResponseWithoutAddedCacheHeader
416416

417417
$this->restoreOriginalSessionIniSettings($ini);
418418
}
419+
420+
public function testCookiesNotSetWithoutRegenerate()
421+
{
422+
$persistence = new PhpSessionPersistence();
423+
$request = new ServerRequest();
424+
$session = $persistence->initializeSessionFromRequest($request);
425+
426+
$response = new Response();
427+
$response = $persistence->persistSession($session, $response);
428+
429+
$this->assertFalse($response->hasHeader('Set-Cookie'));
430+
}
431+
432+
public function testCookiesSetWithoutRegenerate()
433+
{
434+
$persistence = new PhpSessionPersistence();
435+
$request = new ServerRequest();
436+
$session = $persistence->initializeSessionFromRequest($request);
437+
438+
$session->set('foo', 'bar');
439+
440+
$response = new Response();
441+
$response = $persistence->persistSession($session, $response);
442+
443+
$this->assertNotEmpty($response->getHeaderLine('Set-Cookie'));
444+
}
419445
}

0 commit comments

Comments
 (0)