SessionHandlerProxy.php 2.3 KB

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