SessionHandlerProxy.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
  12. /**
  13. * @author Drak <drak@zikula.org>
  14. */
  15. class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
  16. {
  17. protected $handler;
  18. public function __construct(\SessionHandlerInterface $handler)
  19. {
  20. $this->handler = $handler;
  21. $this->wrapper = $handler instanceof \SessionHandler;
  22. $this->saveHandlerName = $this->wrapper || ($handler instanceof StrictSessionHandler && $handler->isWrapper()) ? \ini_get('session.save_handler') : 'user';
  23. }
  24. public function getHandler(): \SessionHandlerInterface
  25. {
  26. return $this->handler;
  27. }
  28. // \SessionHandlerInterface
  29. public function open(string $savePath, string $sessionName): bool
  30. {
  31. return $this->handler->open($savePath, $sessionName);
  32. }
  33. public function close(): bool
  34. {
  35. return $this->handler->close();
  36. }
  37. public function read(#[\SensitiveParameter] string $sessionId): string|false
  38. {
  39. return $this->handler->read($sessionId);
  40. }
  41. public function write(#[\SensitiveParameter] string $sessionId, string $data): bool
  42. {
  43. return $this->handler->write($sessionId, $data);
  44. }
  45. public function destroy(#[\SensitiveParameter] string $sessionId): bool
  46. {
  47. return $this->handler->destroy($sessionId);
  48. }
  49. public function gc(int $maxlifetime): int|false
  50. {
  51. return $this->handler->gc($maxlifetime);
  52. }
  53. public function validateId(#[\SensitiveParameter] string $sessionId): bool
  54. {
  55. return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
  56. }
  57. public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool
  58. {
  59. return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
  60. }
  61. }