@@ -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 ' => '' ,
@@ -116,6 +110,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
116
110
117
111
session_register_shutdown ();
118
112
113
+ $ this ->setMetadataBag ($ metaBag );
119
114
$ this ->setOptions ($ options );
120
115
$ this ->setSaveHandler ($ handler );
121
116
}
@@ -288,7 +283,7 @@ public function getBag($name)
288
283
throw new \InvalidArgumentException (sprintf ('The SessionBagInterface %s is not registered. ' , $ name ));
289
284
}
290
285
291
- if ($ this ->saveHandler -> isActive () && ! $ this ->started ) {
286
+ if (! $ this ->started && $ this ->saveHandler -> isActive () ) {
292
287
$ this ->loadSession ();
293
288
} elseif (!$ this ->started ) {
294
289
$ this ->start ();
@@ -336,7 +331,7 @@ public function isStarted()
336
331
*/
337
332
public function setOptions (array $ options )
338
333
{
339
- if (headers_sent ()) {
334
+ if (headers_sent () || (\ PHP_VERSION_ID >= 50400 && \ PHP_SESSION_ACTIVE === session_status ()) ) {
340
335
return ;
341
336
}
342
337
@@ -391,10 +386,6 @@ public function setSaveHandler($saveHandler = null)
391
386
throw new \InvalidArgumentException ('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null. ' );
392
387
}
393
388
394
- if (headers_sent ($ file , $ line )) {
395
- throw new \RuntimeException (sprintf ('Failed to set the session handler because headers have already been sent by "%s" at line %d. ' , $ file , $ line ));
396
- }
397
-
398
389
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
399
390
if (!$ saveHandler instanceof AbstractProxy && $ saveHandler instanceof \SessionHandlerInterface) {
400
391
$ saveHandler = new SessionHandlerProxy ($ saveHandler );
@@ -404,6 +395,10 @@ public function setSaveHandler($saveHandler = null)
404
395
}
405
396
$ this ->saveHandler = $ saveHandler ;
406
397
398
+ if (headers_sent () || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status ())) {
399
+ return ;
400
+ }
401
+
407
402
if ($ this ->saveHandler instanceof \SessionHandlerInterface) {
408
403
if (\PHP_VERSION_ID >= 50400 ) {
409
404
session_set_save_handler ($ this ->saveHandler , false );
0 commit comments