SessionHandlerProxy.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #[\ReturnTypeWillChange]
  35. public function open($savePath, $sessionName)
  36. {
  37. return (bool) $this->handler->open($savePath, $sessionName);
  38. }
  39. /**
  40. * @return bool
  41. */
  42. #[\ReturnTypeWillChange]
  43. public function close()
  44. {
  45. return (bool) $this->handler->close();
  46. }
  47. /**
  48. * @return string
  49. */
  50. #[\ReturnTypeWillChange]
  51. public function read($sessionId)
  52. {
  53. return (string) $this->handler->read($sessionId);
  54. }
  55. /**
  56. * @return bool
  57. */
  58. #[\ReturnTypeWillChange]
  59. public function write($sessionId, $data)
  60. {
  61. return (bool) $this->handler->write($sessionId, $data);
  62. }
  63. /**
  64. * @return bool
  65. */
  66. #[\ReturnTypeWillChange]
  67. public function destroy($sessionId)
  68. {
  69. return (bool) $this->handler->destroy($sessionId);
  70. }
  71. /**
  72. * @return int|false
  73. */
  74. #[\ReturnTypeWillChange]
  75. public function gc($maxlifetime)
  76. {
  77. return $this->handler->gc($maxlifetime);
  78. }
  79. /**
  80. * @return bool
  81. */
  82. #[\ReturnTypeWillChange]
  83. public function validateId($sessionId)
  84. {
  85. return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
  86. }
  87. /**
  88. * @return bool
  89. */
  90. #[\ReturnTypeWillChange]
  91. public function updateTimestamp($sessionId, $data)
  92. {
  93. return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
  94. }
  95. }