PhpBridgeSessionStorage.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /**
  20. * @param AbstractProxy|\SessionHandlerInterface|null $handler
  21. */
  22. public function __construct($handler = null, MetadataBag $metaBag = null)
  23. {
  24. if (!\extension_loaded('session')) {
  25. throw new \LogicException('PHP extension "session" is required.');
  26. }
  27. $this->setMetadataBag($metaBag);
  28. $this->setSaveHandler($handler);
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function start()
  34. {
  35. if ($this->started) {
  36. return true;
  37. }
  38. $this->loadSession();
  39. return true;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function clear()
  45. {
  46. // clear out the bags and nothing else that may be set
  47. // since the purpose of this driver is to share a handler
  48. foreach ($this->bags as $bag) {
  49. $bag->clear();
  50. }
  51. // reconnect the bags to the session
  52. $this->loadSession();
  53. }
  54. }