PhpBridgeSessionStorage.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. public function clear(): void
  36. {
  37. // clear out the bags and nothing else that may be set
  38. // since the purpose of this driver is to share a handler
  39. foreach ($this->bags as $bag) {
  40. $bag->clear();
  41. }
  42. // reconnect the bags to the session
  43. $this->loadSession();
  44. }
  45. }