SessionInterface.php 3.1 KB

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