22 class_exists(AttributeBag::class);
23 class_exists(FlashBag::class);
24 class_exists(SessionBagProxy::class);
30 class Session implements SessionInterface, \IteratorAggregate, \Countable
35 private $attributeName;
37 private $usageIndex = 0;
44 $this->attributeName = $attributes->getName();
47 $flashes = $flashes ?:
new FlashBag();
48 $this->flashName = $flashes->getName();
57 return $this->storage->start();
63 public function has($name)
65 return $this->getAttributeBag()->has($name);
71 public function get($name, $default =
null)
73 return $this->getAttributeBag()->get($name, $default);
79 public function set($name, $value)
81 $this->getAttributeBag()->set($name, $value);
89 return $this->getAttributeBag()->all();
95 public function replace(array $attributes)
97 $this->getAttributeBag()->replace($attributes);
103 public function remove($name)
105 return $this->getAttributeBag()->remove($name);
113 $this->getAttributeBag()->clear();
121 return $this->storage->isStarted();
131 return new \ArrayIterator($this->getAttributeBag()->
all());
141 return \count($this->getAttributeBag()->
all());
146 return $this->usageIndex;
157 foreach ($this->data as &$data) {
171 $this->storage->clear();
173 return $this->
migrate(
true, $lifetime);
179 public function migrate($destroy =
false, $lifetime =
null)
181 return $this->storage->regenerate($destroy, $lifetime);
189 $this->storage->save();
197 return $this->storage->getId();
205 if ($this->storage->getId() !== $id) {
206 $this->storage->setId($id);
215 return $this->storage->getName();
223 $this->storage->setName($name);
233 return $this->storage->getMetadataBag();
241 $this->storage->registerBag(
new SessionBagProxy($bag, $this->data, $this->usageIndex));
249 $bag = $this->storage->getBag($name);
251 return method_exists($bag,
'getBag') ? $bag->getBag() : $bag;
261 return $this->
getBag($this->flashName);
271 return $this->
getBag($this->attributeName);