8000 [HttpFoundation] When session is active, do not change options · symfony/symfony@e54c292 · GitHub
[go: up one dir, main page]

Skip to content

Commit e54c292

Browse files
srozenicolas-grekas
authored andcommitted
[HttpFoundation] When session is active, do not change options
1 parent 85bd5dd commit e54c292

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,24 @@ public function __construct(array $options = array(), $handler = null, MetadataB
104104
{
105105
$this->setMetadataBag($metaBag);
106106

107-
if (PHP_VERSION_ID >= 70200 && \PHP_SESSION_ACTIVE === session_status()) {
108-
if (!empty($options) || null !== $handler) {
109-
throw new \LogicException('Cannot change options or handler of an active session');
110-
}
111-
} else {
112-
$options += array(
113-
// disable by default because it's managed by HeaderBag (if used)
114-
'cache_limiter' => '',
115-
'use_cookies' => 1,
116-
);
107+
if (\PHP_SESSION_ACTIVE === session_status()) {
108+
return;
109+
}
117110

118-
if (\PHP_VERSION_ID >= 50400) {
119-
session_register_shutdown();
120-
} else {
121-
register_shutdown_function('session_write_close');
122-
}
111+
$options += array(
112+
// disable by default because it's managed by HeaderBag (if used)
113+
'cache_limiter' => '',
114+
'use_cookies' => 1,
115+
);
123116

124-
$this->setOptions($options);
125-
$this->setSaveHandler($handler);
117+
if (\PHP_VERSION_ID >= 50400) {
118+
session_register_shutdown();
119+
} else {
120+
register_shutdown_function('session_write_close');
126121
}
122+
123+
$this->setOptions($options);
124+
$this->setSaveHandler($handler);
127125
}
128126

129127
/**

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,14 @@ public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
280280
$this->assertTrue(true);
281281
}
282282

283-
/**
284-
* @expectedException \LogicException
285-
*/
286-
public function testCannotSetSessionOptionsOnceSessionStarted()
283+
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
287284
{
288-
if (PHP_VERSION_ID < 70200) {
289-
$this->markTestSkipped('Limitation from PHP 7.2 only');
290-
}
291-
292285
session_start();
293286
$this->getStorage(array(
294287
'name' => 'something-else',
295288
));
289+
290+
// Assert no exception has been thrown by `getStorage()`
291+
$this->assertTrue(true);
296292
}
297293
}

0 commit comments

Comments
 (0)
0