PhpBridgeSessionStorage.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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|null $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. public function start(): bool
  28. {
  29. if ($this->started) {
  30. return true;
  31. }
  32. $this->loadSession();
  33. return true;
  34. }
  35. /**
  36. * @return void
  37. */
  38. public function clear()
  39. {
  40. // clear out the bags and nothing else that may be set
  41. // since the purpose of this driver is to share a handler
  42. foreach ($this->bags as $bag) {
  43. $bag->clear();
  44. }
  45. // reconnect the bags to the session
  46. $this->loadSession();
  47. }
  48. }