PhpBridgeSessionStorage.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
  41. // This condition matches only PHP 5.3 + internal save handlers
  42. $this->saveHandler->setActive(true);
  43. }
  44. return true;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function clear()
  50. {
  51. // clear out the bags and nothing else that may be set
  52. // since the purpose of this driver is to share a handler
  53. foreach ($this->bags as $bag) {
  54. $bag->clear();
  55. }
  56. // reconnect the bags to the session
  57. $this->loadSession();
  58. }
  59. }