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

Commit

Permalink
Merge branch 'hotfix/3429'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ class SessionManager extends AbstractManager
*/
protected $validatorChain;

/**
* Destructor
* Ensures that writeClose is called.
*
* @return void
*/
public function __destruct()
{
$this->writeClose();
}

/**
* Does a session exist and is it currently active?
*
Expand Down Expand Up @@ -149,10 +160,12 @@ public function writeClose()
// flushed to the session handler. As such, we now mark the storage
// object isImmutable.
$storage = $this->getStorage();
$_SESSION = (array) $storage;
session_write_close();
$storage->fromArray($_SESSION);
$storage->markImmutable();
if (!$storage->isImmutable()) {
$_SESSION = (array) $storage;
session_write_close();
$storage->fromArray($_SESSION);
$storage->markImmutable();
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ public function testCallingWriteCloseMarksStorageAsImmutable()
$this->assertTrue($storage->isImmutable());
}

/**
* @runInSeparateProcess
*/
public function testCallingDestructorMarksStorageAsImmutable()
{
$this->manager->start();
$storage = $this->manager->getStorage();
$storage['foo'] = 'bar';
$this->manager = null;
$this->assertTrue($storage->isImmutable());
}

/**
* @runInSeparateProcess
*/
Expand Down

0 comments on commit b63de1e

Please sign in to comment.