PhpBridgeSessionStorage.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Storage;
  11. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  12. /**
  13. * Allows session to be started by PHP and managed by Symfony.
  14. *
  15. * @author Drak <drak@zikula.org>
  16. */
  17. class PhpBridgeSessionStorage extends NativeSessionStorage
  18. {
  19. public function __construct(AbstractProxy|\SessionHandlerInterface $handler = null, MetadataBag $metaBag = null)
  20. {
  21. if (!\extension_loaded('session')) {
  22. throw new \LogicException('PHP extension "session" is required.');
  23. }
  24. $this->setMetadataBag($metaBag);
  25. $this->setSaveHandler($handler);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function start(): bool
  31. {
  32. if ($this->started) {
  33. return true;
  34. }
  35. $this->loadSession();
  36. return true;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function clear()
  42. {
  43. // clear out the bags and nothing else that may be set
  44. // since the purpose of this driver is to share a handler
  45. foreach ($this->bags as $bag) {
  46. $bag->clear();
  47. }
  48. // reconnect the bags to the session
  49. $this->loadSession();
  50. }
  51. }