ISession.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Thomas Tanghus <thomas@tanghus.net>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. // use OCP namespace for all classes that are considered public.
  29. // This means that they should be used by apps instead of the internal ownCloud classes
  30. namespace OCP;
  31. use OCP\Session\Exceptions\SessionNotAvailableException;
  32. /**
  33. * Interface ISession
  34. *
  35. * wrap PHP's internal session handling into the ISession interface
  36. * @since 6.0.0
  37. */
  38. interface ISession {
  39. /**
  40. * Set a value in the session
  41. *
  42. * @param string $key
  43. * @param mixed $value
  44. * @since 6.0.0
  45. */
  46. public function set(string $key, $value);
  47. /**
  48. * Get a value from the session
  49. *
  50. * @param string $key
  51. * @return mixed should return null if $key does not exist
  52. * @since 6.0.0
  53. */
  54. public function get(string $key);
  55. /**
  56. * Check if a named key exists in the session
  57. *
  58. * @param string $key
  59. * @return bool
  60. * @since 6.0.0
  61. */
  62. public function exists(string $key): bool;
  63. /**
  64. * Remove a $key/$value pair from the session
  65. *
  66. * @param string $key
  67. * @since 6.0.0
  68. */
  69. public function remove(string $key);
  70. /**
  71. * Reset and recreate the session
  72. * @since 6.0.0
  73. */
  74. public function clear();
  75. /**
  76. * Reopen a session for writing again
  77. *
  78. * @return bool true if the session was actually reopened, otherwise false
  79. * @since 25.0.0
  80. */
  81. public function reopen(): bool;
  82. /**
  83. * Close the session and release the lock
  84. * @since 7.0.0
  85. */
  86. public function close();
  87. /**
  88. * Wrapper around session_regenerate_id
  89. *
  90. * @param bool $deleteOldSession Whether to delete the old associated session file or not.
  91. * @param bool $updateToken Wheater to update the associated auth token
  92. * @return void
  93. * @since 9.0.0, $updateToken added in 14.0.0
  94. */
  95. public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false);
  96. /**
  97. * Wrapper around session_id
  98. *
  99. * @return string
  100. * @throws SessionNotAvailableException
  101. * @since 9.1.0
  102. */
  103. public function getId(): string;
  104. }