SessionHandler.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @link https://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license https://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. use SessionHandlerInterface;
  9. /**
  10. * SessionHandler implements an [[\SessionHandlerInterface]] for handling [[Session]] with custom session storage.
  11. *
  12. * @author Viktor Khokhryakov <viktor.khokhryakov@gmail.com>
  13. * @since 2.0.52
  14. */
  15. class SessionHandler implements SessionHandlerInterface
  16. {
  17. /**
  18. * @var Session
  19. */
  20. private $_session;
  21. public function __construct(Session $session)
  22. {
  23. $this->_session = $session;
  24. }
  25. /**
  26. * @inheritDoc
  27. */
  28. public function close(): bool
  29. {
  30. return $this->_session->closeSession();
  31. }
  32. /**
  33. * @inheritDoc
  34. */
  35. public function destroy($id): bool
  36. {
  37. return $this->_session->destroySession($id);
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. #[\ReturnTypeWillChange]
  43. public function gc($max_lifetime)
  44. {
  45. return $this->_session->gcSession($max_lifetime);
  46. }
  47. /**
  48. * @inheritDoc
  49. */
  50. public function open($path, $name): bool
  51. {
  52. return $this->_session->openSession($path, $name);
  53. }
  54. /**
  55. * @inheritDoc
  56. */
  57. #[\ReturnTypeWillChange]
  58. public function read($id)
  59. {
  60. return $this->_session->readSession($id);
  61. }
  62. /**
  63. * @inheritDoc
  64. */
  65. public function write($id, $data): bool
  66. {
  67. return $this->_session->writeSession($id, $data);
  68. }
  69. }