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