SessionHandlerProxy.php 1.9 KB

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