SessionHandlerProxy.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  12. * @author Drak <drak@zikula.org>
  13. */
  14. class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
  15. {
  16. protected $handler;
  17. /**
  18. * @param \SessionHandlerInterface $handler
  19. */
  20. public function __construct(\SessionHandlerInterface $handler)
  21. {
  22. $this->handler = $handler;
  23. $this->wrapper = ($handler instanceof \SessionHandler);
  24. $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
  25. }
  26. // \SessionHandlerInterface
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function open($savePath, $sessionName)
  31. {
  32. $return = (bool) $this->handler->open($savePath, $sessionName);
  33. if (true === $return) {
  34. $this->active = true;
  35. }
  36. return $return;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function close()
  42. {
  43. $this->active = false;
  44. return (bool) $this->handler->close();
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function read($sessionId)
  50. {
  51. return (string) $this->handler->read($sessionId);
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function write($sessionId, $data)
  57. {
  58. return (bool) $this->handler->write($sessionId, $data);
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function destroy($sessionId)
  64. {
  65. return (bool) $this->handler->destroy($sessionId);
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function gc($maxlifetime)
  71. {
  72. return (bool) $this->handler->gc($maxlifetime);
  73. }
  74. }