菜谱项目

PhpBridgeSessionStorage.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * @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. return true;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function clear()
  44. {
  45. // clear out the bags and nothing else that may be set
  46. // since the purpose of this driver is to share a handler
  47. foreach ($this->bags as $bag) {
  48. $bag->clear();
  49. }
  50. // reconnect the bags to the session
  51. $this->loadSession();
  52. }
  53. }