SessionBagProxy.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpFoundation\Session;
  11. /**
  12. * @author Nicolas Grekas <p@tchwork.com>
  13. *
  14. * @internal
  15. */
  16. final class SessionBagProxy implements SessionBagInterface
  17. {
  18. private $bag;
  19. private $data;
  20. private $hasBeenStarted;
  21. public function __construct(SessionBagInterface $bag, array &$data, &$hasBeenStarted)
  22. {
  23. $this->bag = $bag;
  24. $this->data = &$data;
  25. $this->hasBeenStarted = &$hasBeenStarted;
  26. }
  27. /**
  28. * @return SessionBagInterface
  29. */
  30. public function getBag()
  31. {
  32. return $this->bag;
  33. }
  34. /**
  35. * @return bool
  36. */
  37. public function isEmpty()
  38. {
  39. return empty($this->data[$this->bag->getStorageKey()]);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getName()
  45. {
  46. return $this->bag->getName();
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function initialize(array &$array)
  52. {
  53. $this->hasBeenStarted = true;
  54. $this->data[$this->bag->getStorageKey()] = &$array;
  55. $this->bag->initialize($array);
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function getStorageKey()
  61. {
  62. return $this->bag->getStorageKey();
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function clear()
  68. {
  69. return $this->bag->clear();
  70. }
  71. }