Session.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. namespace OC\Session;
  9. use OCP\ISession;
  10. /**
  11. * @template-implements \ArrayAccess<string,mixed>
  12. */
  13. abstract class Session implements \ArrayAccess, ISession {
  14. /**
  15. * @var bool
  16. */
  17. protected $sessionClosed = false;
  18. /**
  19. * $name serves as a namespace for the session keys
  20. *
  21. * @param string $name
  22. */
  23. abstract public function __construct(string $name);
  24. /**
  25. * @param mixed $offset
  26. * @return bool
  27. */
  28. public function offsetExists($offset): bool {
  29. return $this->exists($offset);
  30. }
  31. /**
  32. * @param mixed $offset
  33. * @return mixed
  34. */
  35. #[\ReturnTypeWillChange]
  36. public function offsetGet($offset) {
  37. return $this->get($offset);
  38. }
  39. /**
  40. * @param mixed $offset
  41. * @param mixed $value
  42. */
  43. public function offsetSet($offset, $value): void {
  44. $this->set($offset, $value);
  45. }
  46. /**
  47. * @param mixed $offset
  48. */
  49. public function offsetUnset($offset): void {
  50. $this->remove($offset);
  51. }
  52. /**
  53. * Close the session and release the lock
  54. */
  55. public function close() {
  56. $this->sessionClosed = true;
  57. }
  58. }