AbstractProxy.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. * AbstractProxy.
  13. *
  14. * @author Drak <drak@zikula.org>
  15. */
  16. abstract class AbstractProxy
  17. {
  18. /**
  19. * Flag if handler wraps an internal PHP session handler (using \SessionHandler).
  20. *
  21. * @var boolean
  22. */
  23. protected $wrapper = false;
  24. /**
  25. * @var boolean
  26. */
  27. protected $active = false;
  28. /**
  29. * @var string
  30. */
  31. protected $saveHandlerName;
  32. /**
  33. * Gets the session.save_handler name.
  34. *
  35. * @return string
  36. */
  37. public function getSaveHandlerName()
  38. {
  39. return $this->saveHandlerName;
  40. }
  41. /**
  42. * Is this proxy handler and instance of \SessionHandlerInterface.
  43. *
  44. * @return boolean
  45. */
  46. public function isSessionHandlerInterface()
  47. {
  48. return ($this instanceof \SessionHandlerInterface);
  49. }
  50. /**
  51. * Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
  52. *
  53. * @return bool
  54. */
  55. public function isWrapper()
  56. {
  57. return $this->wrapper;
  58. }
  59. /**
  60. * Has a session started?
  61. *
  62. * @return bool
  63. */
  64. public function isActive()
  65. {
  66. return $this->active;
  67. }
  68. /**
  69. * Sets the active flag.
  70. *
  71. * @param bool $flag
  72. */
  73. public function setActive($flag)
  74. {
  75. $this->active = (bool) $flag;
  76. }
  77. /**
  78. * Gets the session ID.
  79. *
  80. * @return string
  81. */
  82. public function getId()
  83. {
  84. return session_id();
  85. }
  86. /**
  87. * Sets the session ID.
  88. *
  89. * @param string $id
  90. */
  91. public function setId($id)
  92. {
  93. if ($this->isActive()) {
  94. throw new \LogicException('Cannot change the ID of an active session');
  95. }
  96. session_id($id);
  97. }
  98. /**
  99. * Gets the session name.
  100. *
  101. * @return string
  102. */
  103. public function getName()
  104. {
  105. return session_name();
  106. }
  107. /**
  108. * Sets the session name.
  109. *
  110. * @param string $name
  111. */
  112. public function setName($name)
  113. {
  114. if ($this->isActive()) {
  115. throw new \LogicException('Cannot change the name of an active session');
  116. }
  117. session_name($name);
  118. }
  119. }