PhpBridgeSessionStorage.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Handler\NativeSessionHandler;
  12. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  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. * @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
  22. * @param MetadataBag $metaBag MetadataBag
  23. */
  24. public function __construct($handler = null, MetadataBag $metaBag = null)
  25. {
  26. $this->setMetadataBag($metaBag);
  27. $this->setSaveHandler($handler);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function start()
  33. {
  34. if ($this->started) {
  35. return true;
  36. }
  37. $this->loadSession();
  38. if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
  39. // This condition matches only PHP 5.3 + internal save handlers
  40. $this->saveHandler->setActive(true);
  41. }
  42. return true;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function clear()
  48. {
  49. // clear out the bags and nothing else that may be set
  50. // since the purpose of this driver is to share a handler
  51. foreach ($this->bags as $bag) {
  52. $bag->clear();
  53. }
  54. // reconnect the bags to the session
  55. $this->loadSession();
  56. }
  57. }