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/107'
Browse files Browse the repository at this point in the history
Close #107
Fixes #104
  • Loading branch information
weierophinney committed Jan 31, 2018
2 parents 2b57159 + 29cd657 commit b5acadc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#107](https://github.com/zendframework/zend-session/pull/107) fixes an error
raised by `ini_set()` within `SessionConfig::setStorageOption()` that occurs
for certain INI values that cannot be set if the session is active. When this
situation occurs, the class performs a `session_write_close()`, sets the new
INI value, and then restarts the session. As such, we recommend that you
either set production INI values in your production `php.ini`, and/or always
pass your fully configured session manager to container instances you create.

## 2.8.3 - 2017-12-01

Expand Down
19 changes: 18 additions & 1 deletion src/Config/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,24 @@ public function setStorageOption($storageName, $storageValue)
break;
}

$result = ini_set($key, (string) $storageValue);
$iniGet = ini_get($key);
$storageValue = (string) $storageValue;
if (false !== $iniGet && (string) $iniGet === $storageValue) {
return $this;
}

$sessionRequiresRestart = false;
if (session_status() == PHP_SESSION_ACTIVE) {
session_write_close();
$sessionRequiresRestart = true;
}

$result = ini_set($key, $storageValue);

if ($sessionRequiresRestart) {
session_start();
}

if (false === $result) {
throw new Exception\InvalidArgumentException(
"'{$key}' is not a valid sessions-related ini setting."
Expand Down
17 changes: 17 additions & 0 deletions test/Config/SessionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ public function testNameAltersIniSetting()
$this->assertEquals('FOOBAR', ini_get('session.name'));
}

public function testNameAltersIniSettingAfterSessionStart()
{
session_start();

$this->config->setName('FOOBAR');
$this->assertEquals('FOOBAR', ini_get('session.name'));
}

public function testIdempotentNameAltersIniSettingWithSameValueAfterSessionStart()
{
$this->config->setName('FOOBAR');
session_start();

$this->config->setName('FOOBAR');
$this->assertEquals('FOOBAR', ini_get('session.name'));
}

// session.save_handler

public function testSaveHandlerDefaultsToIniSettings()
Expand Down

0 comments on commit b5acadc

Please sign in to comment.