File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
src/Symfony/Component/HttpFoundation Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,9 @@ public function registerBag(SessionBagInterface $bag)
253
253
*/
254
254
public function getBag ($ name )
255
255
{
256
- return $ this ->storage ->getBag ($ name )->getBag ();
256
+ $ bag = $ this ->storage ->getBag ($ name );
257
+
258
+ return method_exists ($ bag , 'getBag ' ) ? $ bag ->getBag () : $ bag ;
257
259
}
258
260
259
261
/**
Original file line number Diff line number Diff line change 15
15
use Symfony \Component \HttpFoundation \Session \Attribute \AttributeBag ;
16
16
use Symfony \Component \HttpFoundation \Session \Flash \FlashBag ;
17
17
use Symfony \Component \HttpFoundation \Session \Session ;
18
+ use Symfony \Component \HttpFoundation \Session \SessionBagProxy ;
18
19
use Symfony \Component \HttpFoundation \Session \Storage \MockArraySessionStorage ;
19
20
20
21
/**
@@ -260,4 +261,28 @@ public function testIsEmpty()
260
261
$ flash ->get ('hello ' );
261
262
$ this ->assertTrue ($ this ->session ->isEmpty ());
262
263
}
264
+
265
+ public function testGetBagWithBagImplementingGetBag ()
266
+ {
267
+ $ bag = new AttributeBag ();
268
+ $ bag ->setName ('foo ' );
269
+
270
+ $ storage = new MockArraySessionStorage ();
271
+ $ storage ->registerBag ($ bag );
272
+
273
+ $ this ->assertSame ($ bag , (new Session ($ storage ))->getBag ('foo ' ));
274
+ }
275
+
276
+ public function testGetBagWithBagNotImplementingGetBag ()
277
+ {
278
+ $ data = [];
279
+
280
+ $ bag = new AttributeBag ();
281
+ $ bag ->setName ('foo ' );
282
+
283
+ $ storage = new MockArraySessionStorage ();
284
+ $ storage ->registerBag (new SessionBagProxy ($ bag , $ data , $ usageIndex ));
285
+
286
+ $ this ->assertSame ($ bag , (new Session ($ storage ))->getBag ('foo ' ));
287
+ }
263
288
}
You can’t perform that action at this time.
0 commit comments