Skip to content
Permalink
Browse files

bug #32137 [HttpFoundation] fix accessing session bags (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] fix accessing session bags

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30682
| License       | MIT
| Doc PR        |

Commits
-------

7a4570d fix accessing session bags
  • Loading branch information...
fabpot committed Jun 26, 2019
2 parents c511e46 + 7a4570d commit c042b5b6a5d8169711374d2ddf0030832b821765
@@ -253,7 +253,9 @@ public function registerBag(SessionBagInterface $bag)
*/
public function getBag($name)
{
return $this->storage->getBag($name)->getBag();
$bag = $this->storage->getBag($name);
return method_exists($bag, 'getBag') ? $bag->getBag() : $bag;
}
/**
@@ -15,6 +15,7 @@
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionBagProxy;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
/**
@@ -260,4 +261,28 @@ public function testIsEmpty()
$flash->get('hello');
$this->assertTrue($this->session->isEmpty());
}
public function testGetBagWithBagImplementingGetBag()
{
$bag = new AttributeBag();
$bag->setName('foo');
$storage = new MockArraySessionStorage();
$storage->registerBag($bag);
$this->assertSame($bag, (new Session($storage))->getBag('foo'));
}
public function testGetBagWithBagNotImplementingGetBag()
{
$data = [];
$bag = new AttributeBag();
$bag->setName('foo');
$storage = new MockArraySessionStorage();
$storage->registerBag(new SessionBagProxy($bag, $data, $usageIndex));
$this->assertSame($bag, (new Session($storage))->getBag('foo'));
}
}

0 comments on commit c042b5b

Please sign in to comment.
You can’t perform that action at this time.