10000 [WIP][HttpFoundation] Trap fatal configuration condition. · Pull Request #4255 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][HttpFoundation] Trap fatal configuration condition. #4255

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

Closed
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class NativeSessionStorage implements SessionStorageInterface
* @see http://php.net/session.configuration for options
* but we omit 'session.' from the beginning of the keys for convenience.
*
* auto_start, "0"
* ("auto_start", is not supported as it tells PHP to start a session before
* PHP starts to execute user-land code. Setting during runtime has no effect).
*
* cache_limiter, "nocache" (use "0" to prevent headers from being sent entirely).
* cookie_domain, ""
* cookie_httponly, ""
Expand Down Expand Up @@ -95,8 +97,10 @@ class NativeSessionStorage implements SessionStorageInterface
*/
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
{
// sensible defaults
ini_set('session.auto_start', 0); // by default we prefer to explicitly start the session using the class.
if (ini_get('session.auto_start')) {
throw new \RuntimeException('PHP ini setting session.auto_start is set to 1 and must be set to 0');
}

ini_set('session.cache_limiter', ''); // disable by default because it's managed by HeaderBag (if used)
ini_set('session.use_cookies', 1);

Expand Down Expand Up @@ -256,9 +260,7 @@ public function getBag($name)
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
}

if (ini_get('session.auto_start') && !$this->started) {
$this->start();
} elseif ($this->saveHandler->isActive() && !$this->started) {
if ($this->saveHandler->isActive() && !$this->started) {
$this->loadSession();
}

Expand Down Expand Up @@ -302,7 +304,7 @@ public function getMetadataBag()
public function setOptions(array $options)
{
$validOptions = array_flip(array(
'auto_start', 'cache_limiter', 'cookie_domain', 'cookie_httponly',
'cache_limiter', 'cookie_domain', 'cookie_httponly',
'cookie_lifetime', 'cookie_path', 'cookie_secure',
'entropy_file', 'entropy_length', 'gc_divisor',
'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public function testRegisterBagException()
$storage->getBag('non_existing');
}

/**
* @expectedException \RuntimeException
*/
public function test__constructException()
{
ini_set('session.auto_start', 1);
$storage = $this->getStorage();
}

public function testGetId()
{
$storage = $this->getStorage();
Expand Down
0