SessionHandlerProxy.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public function __construct(
  18. protected \SessionHandlerInterface $handler,
  19. ) {
  20. $this->wrapper = $handler instanceof \SessionHandler;
  21. $this->saveHandlerName = $this->wrapper || ($handler instanceof StrictSessionHandler && $handler->isWrapper()) ? \ini_get('session.save_handler') : 'user';
  22. }
  23. public function getHandler(): \SessionHandlerInterface
  24. {
  25. return $this->handler;
  26. }
  27. // \SessionHandlerInterface
  28. public function open(string $savePath, string $sessionName): bool
  29. {
  30. return $this->handler->open($savePath, $sessionName);
  31. }
  32. public function close(): bool
  33. {
  34. return $this->handler->close();
  35. }
  36. public function read(#[\SensitiveParameter] string $sessionId): string|false
  37. {
  38. return $this->handler->read($sessionId);
  39. }
  40. public function write(#[\SensitiveParameter] string $sessionId, string $data): bool
  41. {
  42. return $this->handler->write($sessionId, $data);
  43. }
  44. public function destroy(#[\SensitiveParameter] string $sessionId): bool
  45. {
  46. return $this->handler->destroy($sessionId);
  47. }
  48. public function gc(int $maxlifetime): int|false
  49. {
  50. return $this->handler->gc($maxlifetime);
  51. }
  52. public function validateId(#[\SensitiveParameter] string $sessionId): bool
  53. {
  54. return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
  55. }
  56. public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool
  57. {
  58. return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
  59. }
  60. }