PhpBridgeSessionStorage.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }