菜谱项目

SessionInterface.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 True if session started
  23. *
  24. * @throws \RuntimeException if session fails to start
  25. */
  26. public function start();
  27. /**
  28. * Returns the session ID.
  29. *
  30. * @return string The session ID
  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 mixed The session name
  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 True if session invalidated, false if error
  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 True if session migrated, false if error
  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 true if the attribute is defined, false otherwise
  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 Attributes
  114. */
  115. public function all();
  116. /**
  117. * Sets attributes.
  118. *
  119. * @param array $attributes Attributes
  120. */
  121. public function replace(array $attributes);
  122. /**
  123. * Removes an attribute.
  124. *
  125. * @param string $name
  126. *
  127. * @return mixed The removed value or null when it does not exist
  128. */
  129. public function remove($name);
  130. /**
  131. * Clears all attributes.
  132. */
  133. public function clear();
  134. /**
  135. * Checks if the session was started.
  136. *
  137. * @return bool
  138. */
  139. public function isStarted();
  140. /**
  141. * Registers a SessionBagInterface with the session.
  142. */
  143. public function registerBag(SessionBagInterface $bag);
  144. /**
  145. * Gets a bag instance by name.
  146. *
  147. * @param string $name
  148. *
  149. * @return SessionBagInterface
  150. */
  151. public function getBag($name);
  152. /**
  153. * Gets session meta.
  154. *
  155. * @return MetadataBag
  156. */
  157. public function getMetadataBag();
  158. }