MarshallingSessionHandler.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\Handler;
  11. use Symfony\Component\Cache\Marshaller\MarshallerInterface;
  12. /**
  13. * @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
  14. */
  15. class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
  16. {
  17. private $handler;
  18. private $marshaller;
  19. public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller)
  20. {
  21. $this->handler = $handler;
  22. $this->marshaller = $marshaller;
  23. }
  24. /**
  25. * @return bool
  26. */
  27. #[\ReturnTypeWillChange]
  28. public function open($savePath, $name)
  29. {
  30. return $this->handler->open($savePath, $name);
  31. }
  32. /**
  33. * @return bool
  34. */
  35. #[\ReturnTypeWillChange]
  36. public function close()
  37. {
  38. return $this->handler->close();
  39. }
  40. /**
  41. * @return bool
  42. */
  43. #[\ReturnTypeWillChange]
  44. public function destroy($sessionId)
  45. {
  46. return $this->handler->destroy($sessionId);
  47. }
  48. /**
  49. * @return int|false
  50. */
  51. #[\ReturnTypeWillChange]
  52. public function gc($maxlifetime)
  53. {
  54. return $this->handler->gc($maxlifetime);
  55. }
  56. /**
  57. * @return string
  58. */
  59. #[\ReturnTypeWillChange]
  60. public function read($sessionId)
  61. {
  62. return $this->marshaller->unmarshall($this->handler->read($sessionId));
  63. }
  64. /**
  65. * @return bool
  66. */
  67. #[\ReturnTypeWillChange]
  68. public function write($sessionId, $data)
  69. {
  70. $failed = [];
  71. $marshalledData = $this->marshaller->marshall(['data' => $data], $failed);
  72. if (isset($failed['data'])) {
  73. return false;
  74. }
  75. return $this->handler->write($sessionId, $marshalledData['data']);
  76. }
  77. /**
  78. * @return bool
  79. */
  80. #[\ReturnTypeWillChange]
  81. public function validateId($sessionId)
  82. {
  83. return $this->handler->validateId($sessionId);
  84. }
  85. /**
  86. * @return bool
  87. */
  88. #[\ReturnTypeWillChange]
  89. public function updateTimestamp($sessionId, $data)
  90. {
  91. return $this->handler->updateTimestamp($sessionId, $data);
  92. }
  93. }