PhpBridgeSessionStorage.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
  13. /**
  14. * Allows session to be started by PHP and managed by Symfony.
  15. *
  16. * @author Drak <drak@zikula.org>
  17. */
  18. class PhpBridgeSessionStorage extends NativeSessionStorage
  19. {
  20. /**
  21. * Constructor.
  22. *
  23. * @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
  24. * @param MetadataBag $metaBag MetadataBag
  25. */
  26. public function __construct($handler = null, MetadataBag $metaBag = null)
  27. {
  28. $this->setMetadataBag($metaBag);
  29. $this->setSaveHandler($handler);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function start()
  35. {
  36. if ($this->started) {
  37. return true;
  38. }
  39. $this->loadSession();
  40. return true;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function clear()
  46. {
  47. // clear out the bags and nothing else that may be set
  48. // since the purpose of this driver is to share a handler
  49. foreach ($this->bags as $bag) {
  50. $bag->clear();
  51. }
  52. // reconnect the bags to the session
  53. $this->loadSession();
  54. }
  55. }