8000 [HttpFoundation] Fix session-related BC break · symfony/symfony@3eaa188 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3eaa188

Browse files
[HttpFoundation] Fix session-related BC break
1 parent 99f8d85 commit 3eaa188

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ class NativeSessionStorage implements SessionStorageInterface
102102
*/
103103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
104104
{
105-
$this->setMetadataBag($metaBag);
106-
107-
if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
108-
return;
109-
}
110-
111105
$options += array(
112106
// disable by default because it's managed by HeaderBag (if used)
113107
'cache_limiter' => '',
@@ -120,6 +114,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
120114
register_shutdown_function('session_write_close');
121115
}
122116

117+
$this->setMetadataBag($metaBag);
123118
$this->setOptions($options);
124119
$this->setSaveHandler($handler);
125120
}
@@ -292,7 +287,7 @@ public function getBag($name)
292287
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
293288
}
294289

295-
if ($this->saveHandler->isActive() && !$this->started) {
290+
if (!$this->started && $this->saveHandler->isActive()) {
296291
$this->loadSession();
297292
} elseif (!$this->started) {
298293
$this->start();
@@ -340,7 +335,7 @@ public function isStarted()
340335
*/
341336
public function setOptions(array $options)
342337
{
343-
if (headers_sent()) {
338+
if (headers_sent() || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status())) {
344339
return;
345340
}
346341

@@ -395,10 +390,6 @@ public function setSaveHandler($saveHandler = null)
395390
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
396391
}
397392

398-
if (headers_sent($file, $line)) {
399-
throw new \RuntimeException(sprintf('Failed to set the session handler because headers have already been sent by "%s" at line %d.', $file, $line));
400-
}
401-
402393
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
403394
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
404395
$saveHandler = new SessionHandlerProxy($saveHandler);
@@ -408,6 +399,10 @@ public function setSaveHandler($saveHandler = null)
408399
}
409400
$this->saveHandler = $saveHandler;
410401

402+
if (headers_sent() || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status())) {
403+
return;
404+
}
405+
411406
if ($this->saveHandler instanceof \SessionHandlerInterface) {
412407
if (\PHP_VERSION_ID >= 50400) {
413408
session_set_save_handler($this->saveHandler, false);

0 commit comments

Comments
 (0)
0