SessionBagProxy.php 1.6 KB

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