SessionStorageInterface.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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;
  11. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  12. /**
  13. * StorageInterface.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. * @author Drak <drak@zikula.org>
  17. */
  18. interface SessionStorageInterface
  19. {
  20. /**
  21. * Starts the session.
  22. *
  23. * @return bool True if started
  24. *
  25. * @throws \RuntimeException If something goes wrong starting the session.
  26. */
  27. public function start();
  28. /**
  29. * Checks if the session is started.
  30. *
  31. * @return bool True if started, false otherwise
  32. */
  33. public function isStarted();
  34. /**
  35. * Returns the session ID.
  36. *
  37. * @return string The session ID or empty
  38. */
  39. public function getId();
  40. /**
  41. * Sets the session ID.
  42. *
  43. * @param string $id
  44. */
  45. public function setId($id);
  46. /**
  47. * Returns the session name.
  48. *
  49. * @return mixed The session name
  50. */
  51. public function getName();
  52. /**
  53. * Sets the session name.
  54. *
  55. * @param string $name
  56. */
  57. public function setName($name);
  58. /**
  59. * Regenerates id that represents this storage.
  60. *
  61. * This method must invoke session_regenerate_id($destroy) unless
  62. * this interface is used for a storage object designed for unit
  63. * or functional testing where a real PHP session would interfere
  64. * with testing.
  65. *
  66. * Note regenerate+destroy should not clear the session data in memory
  67. * only delete the session data from persistent storage.
  68. *
  69. * Care: When regenerating the session ID no locking is involved in PHP's
  70. * session design. See https://bugs.php.net/bug.php?id=61470 for a discussion.
  71. * So you must make sure the regenerated session is saved BEFORE sending the
  72. * headers with the new ID. Symfony's HttpKernel offers a listener for this.
  73. * See Symfony\Component\HttpKernel\EventListener\SaveSessionListener.
  74. * Otherwise session data could get lost again for concurrent requests with the
  75. * new ID. One result could be that you get logged out after just logging in.
  76. *
  77. * @param bool $destroy Destroy session when regenerating?
  78. * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
  79. * will leave the system settings unchanged, 0 sets the cookie
  80. * to expire with browser session. Time is in seconds, and is
  81. * not a Unix timestamp.
  82. *
  83. * @return bool True if session regenerated, false if error
  84. *
  85. * @throws \RuntimeException If an error occurs while regenerating this storage
  86. */
  87. public function regenerate($destroy = false, $lifetime = null);
  88. /**
  89. * Force the session to be saved and closed.
  90. *
  91. * This method must invoke session_write_close() unless this interface is
  92. * used for a storage object design for unit or functional testing where
  93. * a real PHP session would interfere with testing, in which case
  94. * it should actually persist the session data if required.
  95. *
  96. * @throws \RuntimeException If the session is saved without being started, or if the session
  97. * is already closed.
  98. */
  99. public function save();
  100. /**
  101. * Clear all session data in memory.
  102. */
  103. public function clear();
  104. /**
  105. * Gets a SessionBagInterface by name.
  106. *
  107. * @param string $name
  108. *
  109. * @return SessionBagInterface
  110. *
  111. * @throws \InvalidArgumentException If the bag does not exist
  112. */
  113. public function getBag($name);
  114. /**
  115. * Registers a SessionBagInterface for use.
  116. *
  117. * @param SessionBagInterface $bag
  118. */
  119. public function registerBag(SessionBagInterface $bag);
  120. /**
  121. * @return MetadataBag
  122. */
  123. public function getMetadataBag();
  124. }