SessionBagProxy.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 $usageIndex;
  21. public function __construct(SessionBagInterface $bag, array &$data, &$usageIndex)
  22. {
  23. $this->bag = $bag;
  24. $this->data = &$data;
  25. $this->usageIndex = &$usageIndex;
  26. }
  27. /**
  28. * @return SessionBagInterface
  29. */
  30. public function getBag()
  31. {
  32. ++$this->usageIndex;
  33. return $this->bag;
  34. }
  35. /**
  36. * @return bool
  37. */
  38. public function isEmpty()
  39. {
  40. if (!isset($this->data[$this->bag->getStorageKey()])) {
  41. return true;
  42. }
  43. ++$this->usageIndex;
  44. return empty($this->data[$this->bag->getStorageKey()]);
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function getName()
  50. {
  51. return $this->bag->getName();
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function initialize(array &$array)
  57. {
  58. ++$this->usageIndex;
  59. $this->data[$this->bag->getStorageKey()] = &$array;
  60. $this->bag->initialize($array);
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getStorageKey()
  66. {
  67. return $this->bag->getStorageKey();
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function clear()
  73. {
  74. return $this->bag->clear();
  75. }
  76. }