SessionInterface.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 Boolean True if session started.
  23. *
  24. * @throws \RuntimeException If session fails to start.
  25. *
  26. * @api
  27. */
  28. public function start();
  29. /**
  30. * Returns the session ID.
  31. *
  32. * @return string The session ID.
  33. *
  34. * @api
  35. */
  36. public function getId();
  37. /**
  38. * Sets the session ID
  39. *
  40. * @param string $id
  41. *
  42. * @api
  43. */
  44. public function setId($id);
  45. /**
  46. * Returns the session name.
  47. *
  48. * @return mixed The session name.
  49. *
  50. * @api
  51. */
  52. public function getName();
  53. /**
  54. * Sets the session name.
  55. *
  56. * @param string $name
  57. *
  58. * @api
  59. */
  60. public function setName($name);
  61. /**
  62. * Invalidates the current session.
  63. *
  64. * Clears all session attributes and flashes and regenerates the
  65. * session and deletes the old session from persistence.
  66. *
  67. * @param integer $lifetime Sets the cookie lifetime for the session cookie. A null value
  68. * will leave the system settings unchanged, 0 sets the cookie
  69. * to expire with browser session. Time is in seconds, and is
  70. * not a Unix timestamp.
  71. *
  72. * @return Boolean True if session invalidated, false if error.
  73. *
  74. * @api
  75. */
  76. public function invalidate($lifetime = null);
  77. /**
  78. * Migrates the current session to a new session id while maintaining all
  79. * session attributes.
  80. *
  81. * @param Boolean $destroy Whether to delete the old session or leave it to garbage collection.
  82. * @param integer $lifetime Sets the cookie lifetime for the session cookie. A null value
  83. * will leave the system settings unchanged, 0 sets the cookie
  84. * to expire with browser session. Time is in seconds, and is
  85. * not a Unix timestamp.
  86. *
  87. * @return Boolean True if session migrated, false if error.
  88. *
  89. * @api
  90. */
  91. public function migrate($destroy = false, $lifetime = null);
  92. /**
  93. * Force the session to be saved and closed.
  94. *
  95. * This method is generally not required for real sessions as
  96. * the session will be automatically saved at the end of
  97. * code execution.
  98. */
  99. public function save();
  100. /**
  101. * Checks if an attribute is defined.
  102. *
  103. * @param string $name The attribute name
  104. *
  105. * @return Boolean true if the attribute is defined, false otherwise
  106. *
  107. * @api
  108. */
  109. public function has($name);
  110. /**
  111. * Returns an attribute.
  112. *
  113. * @param string $name The attribute name
  114. * @param mixed $default The default value if not found.
  115. *
  116. * @return mixed
  117. *
  118. * @api
  119. */
  120. public function get($name, $default = null);
  121. /**
  122. * Sets an attribute.
  123. *
  124. * @param string $name
  125. * @param mixed $value
  126. *
  127. * @api
  128. */
  129. public function set($name, $value);
  130. /**
  131. * Returns attributes.
  132. *
  133. * @return array Attributes
  134. *
  135. * @api
  136. */
  137. public function all();
  138. /**
  139. * Sets attributes.
  140. *
  141. * @param array $attributes Attributes
  142. */
  143. public function replace(array $attributes);
  144. /**
  145. * Removes an attribute.
  146. *
  147. * @param string $name
  148. *
  149. * @return mixed The removed value
  150. *
  151. * @api
  152. */
  153. public function remove($name);
  154. /**
  155. * Clears all attributes.
  156. *
  157. * @api
  158. */
  159. public function clear();
  160. /**
  161. * Checks if the session was started.
  162. *
  163. * @return Boolean
  164. */
  165. public function isStarted();
  166. /**
  167. * Registers a SessionBagInterface with the session.
  168. *
  169. * @param SessionBagInterface $bag
  170. */
  171. public function registerBag(SessionBagInterface $bag);
  172. /**
  173. * Gets a bag instance by name.
  174. *
  175. * @param string $name
  176. *
  177. * @return SessionBagInterface
  178. */
  179. public function getBag($name);
  180. /**
  181. * Gets session meta.
  182. *
  183. * @return MetadataBag
  184. */
  185. public function getMetadataBag();
  186. }