SessionInterface.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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;
  11. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  12. /**
  13. * Interface for the session.
  14. *
  15. * @author Drak <drak@zikula.org>
  16. */
  17. interface SessionInterface
  18. {
  19. /**
  20. * Starts the session storage.
  21. *
  22. * @return bool
  23. *
  24. * @throws \RuntimeException if session fails to start
  25. */
  26. public function start();
  27. /**
  28. * Returns the session ID.
  29. *
  30. * @return string
  31. */
  32. public function getId();
  33. /**
  34. * Sets the session ID.
  35. *
  36. * @param string $id
  37. */
  38. public function setId($id);
  39. /**
  40. * Returns the session name.
  41. *
  42. * @return string
  43. */
  44. public function getName();
  45. /**
  46. * Sets the session name.
  47. *
  48. * @param string $name
  49. */
  50. public function setName($name);
  51. /**
  52. * Invalidates the current session.
  53. *
  54. * Clears all session attributes and flashes and regenerates the
  55. * session and deletes the old session from persistence.
  56. *
  57. * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
  58. * will leave the system settings unchanged, 0 sets the cookie
  59. * to expire with browser session. Time is in seconds, and is
  60. * not a Unix timestamp.
  61. *
  62. * @return bool
  63. */
  64. public function invalidate($lifetime = null);
  65. /**
  66. * Migrates the current session to a new session id while maintaining all
  67. * session attributes.
  68. *
  69. * @param bool $destroy Whether to delete the old session or leave it to garbage collection
  70. * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
  71. * will leave the system settings unchanged, 0 sets the cookie
  72. * to expire with browser session. Time is in seconds, and is
  73. * not a Unix timestamp.
  74. *
  75. * @return bool
  76. */
  77. public function migrate($destroy = false, $lifetime = null);
  78. /**
  79. * Force the session to be saved and closed.
  80. *
  81. * This method is generally not required for real sessions as
  82. * the session will be automatically saved at the end of
  83. * code execution.
  84. */
  85. public function save();
  86. /**
  87. * Checks if an attribute is defined.
  88. *
  89. * @param string $name The attribute name
  90. *
  91. * @return bool
  92. */
  93. public function has($name);
  94. /**
  95. * Returns an attribute.
  96. *
  97. * @param string $name The attribute name
  98. * @param mixed $default The default value if not found
  99. *
  100. * @return mixed
  101. */
  102. public function get($name, $default = null);
  103. /**
  104. * Sets an attribute.
  105. *
  106. * @param string $name
  107. * @param mixed $value
  108. */
  109. public function set($name, $value);
  110. /**
  111. * Returns attributes.
  112. *
  113. * @return array
  114. */
  115. public function all();
  116. /**
  117. * Sets attributes.
  118. */
  119. public function replace(array $attributes);
  120. /**
  121. * Removes an attribute.
  122. *
  123. * @param string $name
  124. *
  125. * @return mixed The removed value or null when it does not exist
  126. */
  127. public function remove($name);
  128. /**
  129. * Clears all attributes.
  130. */
  131. public function clear();
  132. /**
  133. * Checks if the session was started.
  134. *
  135. * @return bool
  136. */
  137. public function isStarted();
  138. /**
  139. * Registers a SessionBagInterface with the session.
  140. */
  141. public function registerBag(SessionBagInterface $bag);
  142. /**
  143. * Gets a bag instance by name.
  144. *
  145. * @param string $name
  146. *
  147. * @return SessionBagInterface
  148. */
  149. public function getBag($name);
  150. /**
  151. * Gets session meta.
  152. *
  153. * @return MetadataBag
  154. */
  155. public function getMetadataBag();
  156. }