Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Closed
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
35 changes: 32 additions & 3 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class SessionManager extends AbstractManager
*/
protected $validatorChain;

/**
* @var bool Regenerate session id flag
*/
protected $regenerateSessionId = true;

/**
* Constructor
*
Expand Down Expand Up @@ -284,18 +289,42 @@ public function getId()
return session_id();
}

/**
* Set flag for regenerate session id
*
* @param bool $regenerateSessionId
* @return SessionManager
*/
public function setRegenerateSessionId($regenerateSessionId)
{
$this->regenerateSessionId = (bool) $regenerateSessionId;
return $this;
}

/**
* Get flag for regenerate session id
*
* @return bool
*/
public function getRegenerateSessionId()
{
return $this->regenerateSessionId;
}

/**
* Regenerate id
*
* Regenerate the session ID, using session save handler's
* native ID generation Can safely be called in the middle of a session.
* Regenerate the session ID if `regenerateSessionId` is true, using session save handler's
* native ID generation. Can safely be called in the middle of a session.
*
* @param bool $deleteOldSession
* @return SessionManager
*/
public function regenerateId($deleteOldSession = true)
{
session_regenerate_id((bool) $deleteOldSession);
if ($this->getRegenerateSessionId()) {
session_regenerate_id((bool) $deleteOldSession);
}
return $this;
}

Expand Down
24 changes: 24 additions & 0 deletions test/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,30 @@ public function testRegenerateIdShouldWorkAfterSessionStarted()
$this->assertNotSame($origId, $this->manager->getId());
}

/**
* @runInSeparateProcess
*/
public function testFlagRegenerateIdSetToTrue()
{
$this->manager->setRegenerateSessionId(true);
$this->manager->start();
$origId = $this->manager->getId();
$this->manager->regenerateId();
$this->assertNotSame($origId, $this->manager->getId());
}

/**
* @runInSeparateProcess
*/
public function testFlagRegenerateIdSetToFalse()
{
$this->manager->setRegenerateSessionId(false);
$this->manager->start();
$origId = $this->manager->getId();
$this->manager->regenerateId();
$this->assertSame($origId, $this->manager->getId());
}

/**
* @runInSeparateProcess
*/
Expand Down