8000 minor #21251 [HttpFoundation][Session] Added a convenient method to g… · symfony/symfony@576ae1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 576ae1c

Browse files
committed
minor #21251 [HttpFoundation][Session] Added a convenient method to get AttributeBagInterface (gmponos)
This PR was submitted for the 3.2 branch but it was merged into the 3.3-dev branch instead (closes #21251). Discussion ---------- [HttpFoundation][Session] Added a convenient method to get AttributeBagInterface Added a convenient method inside Session for getting internally the AttributeBagInterface. This way it also helps autocompletion in some IDE. | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | n/a Commits ------- 6e94ac5 Added a convenient method inside Session for getting internally the AttributeBagInterface and have also autompletion
2 parents 431fad0 + 6e94ac5 commit 576ae1c

File tree

1 file changed

+18
-8
lines changed
  • src/Symfony/Component/HttpFoundation/Session

1 file changed

+18
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,47 +76,47 @@ public function start()
7676
*/
7777
public function has($name)
7878
{
79-
return $this->storage->getBag($this->attributeName)->has($name);
79+
return $this->getAttributeBag()->has($name);
8080
}
8181

8282
/**
8383
* {@inheritdoc}
8484
*/
8585
public function get($name, $default = null)
8686
{
87-
return $this->storage->getBag($this->attributeName)->get($name, $default);
87+
return $this->getAttributeBag()->get($name, $default);
8888
}
8989

9090
/**
9191
* {@inheritdoc}
9292
*/
9393
public function set($name, $value)
9494
{
95-
$this->storage->getBag($this->attributeName)->set($name, $value);
95+
$this->getAttributeBag()->set($name, $value);
9696
}
9797

9898
/**
9999
* {@inheritdoc}
100100
*/
101101
public function all()
102102
{
103-
return $this->storage->getBag($this->attributeName)->all();
103+
return $this->getAttributeBag()->all();
104104
}
105105

106106
/**
107107
* {@inheritdoc}
108108
*/
109109
public function replace(array $attributes)
110110
{
111-
$this->storage->getBag($this->attributeName)->replace($attributes);
111+
$this->getAttributeBag()->replace($attributes);
112112
}
113113

114114
/**
115115
* {@inheritdoc}
116116
*/
117117
public function remove($name)
118118
{
119-
return $this->storage->getBag($this->attributeName)->remove($name);
119+
return $this->getAttributeBag()->remove($name);
120120
}
121121

122122
/**
@@ -142,7 +142,7 @@ public function isStarted()
142142
*/
143143
public function getIterator()
144144
{
145-
return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
145+
return new \ArrayIterator($this->getAttributeBag()->all());
146146
}
147147

148148
/**
@@ -152,7 +152,7 @@ public function getIterator()
152152
*/
153153
public function count()
154154
{
155-
return count($this->storage->getBag($this->attributeName)->all());
155+
return count($this->getAttributeBag()->all());
156156
}
157157

158158
/**
@@ -246,4 +246,14 @@ public function getFlashBag()
246246
{
247247
return $this->getBag($this->flashName);
248248
}
249+
250+
/**
251+
* Gets the attributebag interface.
252+
*
253+
* @return AttributeBagInterface
254+
*/
255+
private function getAttributeBag()
256+
{
257+
return $this->storage->getBag($this->attributeName);
258+
}
249259
}

0 commit comments

Comments
 (0)
0