MarshallingSessionHandler.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. public function open($savePath, $name)
  28. {
  29. return $this->handler->open($savePath, $name);
  30. }
  31. /**
  32. * @return bool
  33. */
  34. public function close()
  35. {
  36. return $this->handler->close();
  37. }
  38. /**
  39. * @return bool
  40. */
  41. public function destroy($sessionId)
  42. {
  43. return $this->handler->destroy($sessionId);
  44. }
  45. /**
  46. * @return bool
  47. */
  48. public function gc($maxlifetime)
  49. {
  50. return $this->handler->gc($maxlifetime);
  51. }
  52. /**
  53. * @return string
  54. */
  55. public function read($sessionId)
  56. {
  57. return $this->marshaller->unmarshall($this->handler->read($sessionId));
  58. }
  59. /**
  60. * @return bool
  61. */
  62. public function write($sessionId, $data)
  63. {
  64. $failed = [];
  65. $marshalledData = $this->marshaller->marshall(['data' => $data], $failed);
  66. if (isset($failed['data'])) {
  67. return false;
  68. }
  69. return $this->handler->write($sessionId, $marshalledData['data']);
  70. }
  71. /**
  72. * @return bool
  73. */
  74. public function validateId($sessionId)
  75. {
  76. return $this->handler->validateId($sessionId);
  77. }
  78. /**
  79. * @return bool
  80. */
  81. public function updateTimestamp($sessionId, $data)
  82. {
  83. return $this->handler->updateTimestamp($sessionId, $data);
  84. }
  85. }