@@ -102,12 +102,6 @@ class NativeSessionStorage implements SessionStorageInterface
102
102
*/
103
103
public function __construct (array $ options = array (), $ handler = null , MetadataBag $ metaBag = null )
104
104
{
105
- $ this ->setMetadataBag ($ metaBag );
106
-
107
- if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status ()) {
108
- return ;
109
- }
110
-
111
105
$ options += array (
112
106
// disable by default because it's managed by HeaderBag (if used)
113
107
'cache_limiter ' => '' ,
@@ -120,6 +114,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
120
114
register_shutdown_function ('session_write_close ' );
121
115
}
122
116
117
+ $ this ->setMetadataBag ($ metaBag );
123
118
$ this ->setOptions ($ options );
124
119
$ this ->setSaveHandler ($ handler );
125
120
}
@@ -292,7 +287,7 @@ public function getBag($name)
292
287
throw new \InvalidArgumentException (sprintf ('The SessionBagInterface %s is not registered. ' , $ name ));
293
288
}
294
289
295
- if ($ this ->saveHandler -> isActive () && ! $ this ->started ) {
290
+ if (! $ this ->started && $ this ->saveHandler -> isActive () ) {
296
291
$ this ->loadSession ();
297
292
} elseif (!$ this ->started ) {
298
293
$ this ->start ();
@@ -340,7 +335,7 @@ public function isStarted()
340
335
*/
341
336
public function setOptions (array $ options )
342
337
{
343
- if (headers_sent ()) {
338
+ if (headers_sent () || (\ PHP_VERSION_ID >= 50400 && \ PHP_SESSION_ACTIVE === session_status ()) ) {
344
339
return ;
345
340
}
346
341
@@ -395,10 +390,6 @@ public function setSaveHandler($saveHandler = null)
395
390
throw new \InvalidArgumentException ('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null. ' );
396
391
}
397
392
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
-
402
393
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
403
394
if (!$ saveHandler instanceof AbstractProxy && $ saveHandler instanceof \SessionHandlerInterface) {
404
395
$ saveHandler = new SessionHandlerProxy ($ saveHandler );
@@ -408,6 +399,10 @@ public function setSaveHandler($saveHandler = null)
408
399
}
409
400
$ this ->saveHandler = $ saveHandler ;
410
401
402
+ if (headers_sent () || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status ())) {
403
+ return ;
404
+ }
405
+
411
406
if ($ this ->saveHandler instanceof \SessionHandlerInterface) {
412
407
if (\PHP_VERSION_ID >= 50400 ) {
413
408
session_set_save_handler ($ this ->saveHandler , false );
0 commit comments