8000 [HttpFoundation] Remove hard coded assumptions and replace with API c… · symfony/symfony@eb9bf05 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb9bf05

Browse files
author
Drak
committed
[HttpFoundation] Remove hard coded assumptions and replace with API calls.
1 parent 9a5fc65 commit eb9bf05

File tree

1 file changed

+26
-10
lines changed
  • src/Symfony/Component/HttpFoundation/Session

1 file changed

+26
-10
lines changed

src/Symfony/Component/HttpFoundation/Session/Session.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ class Session implements SessionInterface
3636
*/
3737
protected $storage;
3838

39+
/**
40+
* @var string
41+
*/
42+
private $flashName;
43+
44+
/**
45+
* @var string
46+
*/
47+
private $attributeName;
48+
3949
/**
4050
* Constructor.
4151
*
@@ -46,8 +56,14 @@ class Session implements SessionInterface
4656
public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
4757
{
4858
$this->storage = $storage ?: new NativeSessionStorage();
49-
$this->registerBag($attributes ?: new AttributeBag());
50-
$this->registerBag($flashes ?: new FlashBag());
59+
60+
$attributeBag = $attributes ?: new AttributeBag();
61+
$this->attributeName = $attributeBag->getName();
62+
$this->registerBag($attributeBag);
63+
64+
$flashBag = $flashes ?: new FlashBag();
65+
$this->flashName = $flashBag->getName();
66+
$this->registerBag($flashBag);
5167
}
5268

5369
/**
@@ -63,55 +79,55 @@ public function start()
6379
*/
6480
public function has($name)
6581
{
66-
return $this->storage->getBag('attributes')->has($name);
82+
return $this->storage->getBag($this->attributeName)->has($name);
6783
}
6884

6985
/**
7086
* {@inheritdoc}
7187
*/
7288
public function get($name, $default = null)
7389
{
74-
return $this->storage->getBag('attributes')->get($name, $default);
90+
return $this->storage->getBag($this->attributeName)->get($name, $default);
7591
}
7692

7793
/**
7894
* {@inheritdoc}
7995
*/
8096
public function set($name, $value)
8197
{
82-
$this->storage->getBag('attributes')->set($name, $value);
98+
$this->storage->getBag($this->attributeName)->set($name, $value);
8399
}
84100

85101
/**
86102
* {@inheritdoc}
87103
*/
88104
public function all()
89105
{
90-
return $this->storage->getBag('attributes')->all();
106+
return $this->storage->getBag($this->attributeName)->all();
91107
}
92108

93109
/**
94110
* {@inheritdoc}
95111
*/
96112
public function replace(array $attributes)
97113
{
98-
$this->storage->getBag('attributes')->replace($attributes);
114+
$this->storage->getBag($this->attributeName)->replace($attributes);
99115
}
100116

101117
/**
102118
* {@inheritdoc}
103119
*/
104120
public function remove($name)
105121
{
106-
return $this->storage->getBag('attributes')->remove($name);
122+
return $this->storage->getBag($this->attributeName)->remove($name);
107123
}
108124

109125
/**
110126
* {@inheritdoc}
111127
*/
112128
public function clear()
113129
{
114-
$this->storage->getBag('attributes')->clear();
130+
$this->storage->getBag($this->attributeName)->clear();
115131
}
116132

117133
/**
@@ -201,7 +217,7 @@ public function getBag($name)
201217
*/
202218
public function getFlashBag()
203219
{
204-
return $this->getBag('flashes');
220+
return $this->getBag($this->flashName);
205221
}
206222

207223
// the following methods are kept for compatibility with Symfony 2.0 (they will be removed for Symfony 2.3)

0 commit comments

Comments
 (0)
0