SessionStorageInterface.php 3.8 KB

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