[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/ -> Session.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\HttpFoundation\Session;
  13  
  14  use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
  15  use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  16  use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
  17  use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
  18  use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  19  use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  20  
  21  /**
  22   * Session.
  23   *
  24   * @author Fabien Potencier <fabien@symfony.com>
  25   * @author Drak <drak@zikula.org>
  26   */
  27  class Session implements SessionInterface, \IteratorAggregate, \Countable
  28  {
  29      /**
  30       * Storage driver.
  31       *
  32       * @var SessionStorageInterface
  33       */
  34      protected $storage;
  35  
  36      /**
  37       * @var string
  38       */
  39      private $flashName;
  40  
  41      /**
  42       * @var string
  43       */
  44      private $attributeName;
  45  
  46      /**
  47       * Constructor.
  48       *
  49       * @param SessionStorageInterface $storage    A SessionStorageInterface instance.
  50       * @param AttributeBagInterface   $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
  51       * @param FlashBagInterface       $flashes    A FlashBagInterface instance (defaults null for default FlashBag)
  52       */
  53      public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
  54      {
  55          $this->storage = $storage ?: new NativeSessionStorage();
  56  
  57          $attributes = $attributes ?: new AttributeBag();
  58          $this->attributeName = $attributes->getName();
  59          $this->registerBag($attributes);
  60  
  61          $flashes = $flashes ?: new FlashBag();
  62          $this->flashName = $flashes->getName();
  63          $this->registerBag($flashes);
  64      }
  65  
  66      /**
  67       * {@inheritdoc}
  68       */
  69      public function start()
  70      {
  71          return $this->storage->start();
  72      }
  73  
  74      /**
  75       * {@inheritdoc}
  76       */
  77      public function has($name)
  78      {
  79          return $this->storage->getBag($this->attributeName)->has($name);
  80      }
  81  
  82      /**
  83       * {@inheritdoc}
  84       */
  85      public function get($name, $default = null)
  86      {
  87          return $this->storage->getBag($this->attributeName)->get($name, $default);
  88      }
  89  
  90      /**
  91       * {@inheritdoc}
  92       */
  93      public function set($name, $value)
  94      {
  95          $this->storage->getBag($this->attributeName)->set($name, $value);
  96      }
  97  
  98      /**
  99       * {@inheritdoc}
 100       */
 101      public function all()
 102      {
 103          return $this->storage->getBag($this->attributeName)->all();
 104      }
 105  
 106      /**
 107       * {@inheritdoc}
 108       */
 109      public function replace(array $attributes)
 110      {
 111          $this->storage->getBag($this->attributeName)->replace($attributes);
 112      }
 113  
 114      /**
 115       * {@inheritdoc}
 116       */
 117      public function remove($name)
 118      {
 119          return $this->storage->getBag($this->attributeName)->remove($name);
 120      }
 121  
 122      /**
 123       * {@inheritdoc}
 124       */
 125      public function clear()
 126      {
 127          $this->storage->getBag($this->attributeName)->clear();
 128      }
 129  
 130      /**
 131       * {@inheritdoc}
 132       */
 133      public function isStarted()
 134      {
 135          return $this->storage->isStarted();
 136      }
 137  
 138      /**
 139       * Returns an iterator for attributes.
 140       *
 141       * @return \ArrayIterator An \ArrayIterator instance
 142       */
 143      public function getIterator()
 144      {
 145          return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
 146      }
 147  
 148      /**
 149       * Returns the number of attributes.
 150       *
 151       * @return int The number of attributes
 152       */
 153      public function count()
 154      {
 155          return count($this->storage->getBag($this->attributeName)->all());
 156      }
 157  
 158      /**
 159       * {@inheritdoc}
 160       */
 161      public function invalidate($lifetime = null)
 162      {
 163          $this->storage->clear();
 164  
 165          return $this->migrate(true, $lifetime);
 166      }
 167  
 168      /**
 169       * {@inheritdoc}
 170       */
 171      public function migrate($destroy = false, $lifetime = null)
 172      {
 173          return $this->storage->regenerate($destroy, $lifetime);
 174      }
 175  
 176      /**
 177       * {@inheritdoc}
 178       */
 179      public function save()
 180      {
 181          $this->storage->save();
 182      }
 183  
 184      /**
 185       * {@inheritdoc}
 186       */
 187      public function getId()
 188      {
 189          return $this->storage->getId();
 190      }
 191  
 192      /**
 193       * {@inheritdoc}
 194       */
 195      public function setId($id)
 196      {
 197          $this->storage->setId($id);
 198      }
 199  
 200      /**
 201       * {@inheritdoc}
 202       */
 203      public function getName()
 204      {
 205          return $this->storage->getName();
 206      }
 207  
 208      /**
 209       * {@inheritdoc}
 210       */
 211      public function setName($name)
 212      {
 213          $this->storage->setName($name);
 214      }
 215  
 216      /**
 217       * {@inheritdoc}
 218       */
 219      public function getMetadataBag()
 220      {
 221          return $this->storage->getMetadataBag();
 222      }
 223  
 224      /**
 225       * {@inheritdoc}
 226       */
 227      public function registerBag(SessionBagInterface $bag)
 228      {
 229          $this->storage->registerBag($bag);
 230      }
 231  
 232      /**
 233       * {@inheritdoc}
 234       */
 235      public function getBag($name)
 236      {
 237          return $this->storage->getBag($name);
 238      }
 239  
 240      /**
 241       * Gets the flashbag interface.
 242       *
 243       * @return FlashBagInterface
 244       */
 245      public function getFlashBag()
 246      {
 247          return $this->getBag($this->flashName);
 248      }
 249  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1