ISession.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. // use OCP namespace for all classes that are considered public.
  9. // This means that they should be used by apps instead of the internal Nextcloud classes
  10. namespace OCP;
  11. use OCP\Session\Exceptions\SessionNotAvailableException;
  12. /**
  13. * Interface ISession
  14. *
  15. * wrap PHP's internal session handling into the ISession interface
  16. * @since 6.0.0
  17. */
  18. interface ISession {
  19. /**
  20. * Set a value in the session
  21. *
  22. * @param string $key
  23. * @param mixed $value
  24. * @since 6.0.0
  25. */
  26. public function set(string $key, $value);
  27. /**
  28. * Get a value from the session
  29. *
  30. * @param string $key
  31. * @return mixed should return null if $key does not exist
  32. * @since 6.0.0
  33. */
  34. public function get(string $key);
  35. /**
  36. * Check if a named key exists in the session
  37. *
  38. * @param string $key
  39. * @return bool
  40. * @since 6.0.0
  41. */
  42. public function exists(string $key): bool;
  43. /**
  44. * Remove a $key/$value pair from the session
  45. *
  46. * @param string $key
  47. * @since 6.0.0
  48. */
  49. public function remove(string $key);
  50. /**
  51. * Reset and recreate the session
  52. * @since 6.0.0
  53. */
  54. public function clear();
  55. /**
  56. * Reopen a session for writing again
  57. *
  58. * @return bool true if the session was actually reopened, otherwise false
  59. * @since 25.0.0
  60. */
  61. public function reopen(): bool;
  62. /**
  63. * Close the session and release the lock
  64. * @since 7.0.0
  65. */
  66. public function close();
  67. /**
  68. * Wrapper around session_regenerate_id
  69. *
  70. * @param bool $deleteOldSession Whether to delete the old associated session file or not.
  71. * @param bool $updateToken Wheater to update the associated auth token
  72. * @return void
  73. * @since 9.0.0, $updateToken added in 14.0.0
  74. */
  75. public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false);
  76. /**
  77. * Wrapper around session_id
  78. *
  79. * @return string
  80. * @throws SessionNotAvailableException
  81. * @since 9.1.0
  82. */
  83. public function getId(): string;
  84. }