PhpBridgeSessionStorage.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /**
  12. * Allows session to be started by PHP and managed by Symfony.
  13. *
  14. * @author Drak <drak@zikula.org>
  15. */
  16. class PhpBridgeSessionStorage extends NativeSessionStorage
  17. {
  18. /**
  19. * @param \SessionHandlerInterface|null $handler
  20. * @param MetadataBag $metaBag MetadataBag
  21. */
  22. public function __construct($handler = null, MetadataBag $metaBag = null)
  23. {
  24. $this->setMetadataBag($metaBag);
  25. $this->setSaveHandler($handler);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function start()
  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. }