SessionHandlerProxy.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\Proxy;
  11. /**
  12. * SessionHandler proxy.
  13. *
  14. * @author Drak <drak@zikula.org>
  15. */
  16. class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
  17. {
  18. /**
  19. * @var \SessionHandlerInterface
  20. */
  21. protected $handler;
  22. /**
  23. * Constructor.
  24. *
  25. * @param \SessionHandlerInterface $handler
  26. */
  27. public function __construct(\SessionHandlerInterface $handler)
  28. {
  29. $this->handler = $handler;
  30. $this->wrapper = ($handler instanceof \SessionHandler);
  31. $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
  32. }
  33. // \SessionHandlerInterface
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function open($savePath, $sessionName)
  38. {
  39. $return = (bool) $this->handler->open($savePath, $sessionName);
  40. if (true === $return) {
  41. $this->active = true;
  42. }
  43. return $return;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function close()
  49. {
  50. $this->active = false;
  51. return (bool) $this->handler->close();
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function read($sessionId)
  57. {
  58. return (string) $this->handler->read($sessionId);
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function write($sessionId, $data)
  64. {
  65. return (bool) $this->handler->write($sessionId, $data);
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function destroy($sessionId)
  71. {
  72. return (bool) $this->handler->destroy($sessionId);
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function gc($maxlifetime)
  78. {
  79. return (bool) $this->handler->gc($maxlifetime);
  80. }
  81. }