123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
- namespace Symfony\Component\HttpFoundation\Session;
- use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
- use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
- use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
- use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
- use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
- use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
- use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
- class Session implements SessionInterface
- {
-
- protected $storage;
-
- private $flashName;
-
- private $attributeName;
-
- public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
- {
- $this->storage = $storage ?: new NativeSessionStorage();
- $attributeBag = $attributes ?: new AttributeBag();
- $this->attributeName = $attributeBag->getName();
- $this->registerBag($attributeBag);
- $flashBag = $flashes ?: new FlashBag();
- $this->flashName = $flashBag->getName();
- $this->registerBag($flashBag);
- }
-
- public function start()
- {
- return $this->storage->start();
- }
-
- public function has($name)
- {
- return $this->storage->getBag($this->attributeName)->has($name);
- }
-
- public function get($name, $default = null)
- {
- return $this->storage->getBag($this->attributeName)->get($name, $default);
- }
-
- public function set($name, $value)
- {
- $this->storage->getBag($this->attributeName)->set($name, $value);
- }
-
- public function all()
- {
- return $this->storage->getBag($this->attributeName)->all();
- }
-
- public function replace(array $attributes)
- {
- $this->storage->getBag($this->attributeName)->replace($attributes);
- }
-
- public function remove($name)
- {
- return $this->storage->getBag($this->attributeName)->remove($name);
- }
-
- public function clear()
- {
- $this->storage->getBag($this->attributeName)->clear();
- }
-
- public function invalidate()
- {
- $this->storage->clear();
- return $this->storage->regenerate(true);
- }
-
- public function migrate($destroy = false)
- {
- return $this->storage->regenerate($destroy);
- }
-
- public function save()
- {
- $this->storage->save();
- }
-
- public function getId()
- {
- return $this->storage->getId();
- }
-
- public function setId($id)
- {
- $this->storage->setId($id);
- }
-
- public function getName()
- {
- return $this->storage->getName();
- }
-
- public function setName($name)
- {
- $this->storage->setName($name);
- }
-
- public function registerBag(SessionBagInterface $bag)
- {
- $this->storage->registerBag($bag);
- }
-
- public function getBag($name)
- {
- return $this->storage->getBag($name);
- }
-
- public function getFlashBag()
- {
- return $this->getBag($this->flashName);
- }
-
-
- public function getFlashes()
- {
- return $this->getBag('flashes')->all();
- }
-
- public function setFlashes($values)
- {
- $this->getBag('flashes')->setAll($values);
- }
-
- public function getFlash($name, $default = null)
- {
- return $this->getBag('flashes')->get($name, $default);
- }
-
- public function setFlash($name, $value)
- {
- $this->getBag('flashes')->set($name, $value);
- }
-
- public function hasFlash($name)
- {
- return $this->getBag('flashes')->has($name);
- }
-
- public function removeFlash($name)
- {
- $this->getBag('flashes')->get($name);
- }
-
- public function clearFlashes()
- {
- return $this->getBag('flashes')->clear();
- }
- }
|