SessionInterface.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * @package Grav\Framework\Session
  4. *
  5. * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Framework\Session;
  9. use ArrayIterator;
  10. use IteratorAggregate;
  11. use RuntimeException;
  12. /**
  13. * Class Session
  14. * @package Grav\Framework\Session
  15. * @extends IteratorAggregate<array-key,mixed>
  16. */
  17. interface SessionInterface extends IteratorAggregate
  18. {
  19. /**
  20. * Get current session instance.
  21. *
  22. * @return Session
  23. * @throws RuntimeException
  24. */
  25. public static function getInstance();
  26. /**
  27. * Get session ID
  28. *
  29. * @return string|null Session ID
  30. */
  31. public function getId();
  32. /**
  33. * Set session ID
  34. *
  35. * @param string $id Session ID
  36. * @return $this
  37. */
  38. public function setId($id);
  39. /**
  40. * Get session name
  41. *
  42. * @return string|null
  43. */
  44. public function getName();
  45. /**
  46. * Set session name
  47. *
  48. * @param string $name
  49. * @return $this
  50. */
  51. public function setName($name);
  52. /**
  53. * Sets session.* ini variables.
  54. *
  55. * @param array $options
  56. * @return void
  57. * @see http://php.net/session.configuration
  58. */
  59. public function setOptions(array $options);
  60. /**
  61. * Starts the session storage
  62. *
  63. * @param bool $readonly
  64. * @return $this
  65. * @throws RuntimeException
  66. */
  67. public function start($readonly = false);
  68. /**
  69. * Invalidates the current session.
  70. *
  71. * @return $this
  72. */
  73. public function invalidate();
  74. /**
  75. * Force the session to be saved and closed
  76. *
  77. * @return $this
  78. */
  79. public function close();
  80. /**
  81. * Free all session variables.
  82. *
  83. * @return $this
  84. */
  85. public function clear();
  86. /**
  87. * Returns all session variables.
  88. *
  89. * @return array
  90. */
  91. public function getAll();
  92. /**
  93. * Retrieve an external iterator
  94. *
  95. * @return ArrayIterator Return an ArrayIterator of $_SESSION
  96. * @phpstan-return ArrayIterator<array-key,mixed>
  97. */
  98. #[\ReturnTypeWillChange]
  99. public function getIterator();
  100. /**
  101. * Checks if the session was started.
  102. *
  103. * @return bool
  104. */
  105. public function isStarted();
  106. /**
  107. * Checks if session variable is defined.
  108. *
  109. * @param string $name
  110. * @return bool
  111. */
  112. #[\ReturnTypeWillChange]
  113. public function __isset($name);
  114. /**
  115. * Returns session variable.
  116. *
  117. * @param string $name
  118. * @return mixed
  119. */
  120. #[\ReturnTypeWillChange]
  121. public function __get($name);
  122. /**
  123. * Sets session variable.
  124. *
  125. * @param string $name
  126. * @param mixed $value
  127. * @return void
  128. */
  129. #[\ReturnTypeWillChange]
  130. public function __set($name, $value);
  131. /**
  132. * Removes session variable.
  133. *
  134. * @param string $name
  135. * @return void
  136. */
  137. #[\ReturnTypeWillChange]
  138. public function __unset($name);
  139. }