Session.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\Session;
  27. use OCP\ISession;
  28. /**
  29. * @template-implements \ArrayAccess<string,mixed>
  30. */
  31. abstract class Session implements \ArrayAccess, ISession {
  32. /**
  33. * @var bool
  34. */
  35. protected $sessionClosed = false;
  36. /**
  37. * $name serves as a namespace for the session keys
  38. *
  39. * @param string $name
  40. */
  41. abstract public function __construct(string $name);
  42. /**
  43. * @param mixed $offset
  44. * @return bool
  45. */
  46. public function offsetExists($offset): bool {
  47. return $this->exists($offset);
  48. }
  49. /**
  50. * @param mixed $offset
  51. * @return mixed
  52. */
  53. #[\ReturnTypeWillChange]
  54. public function offsetGet($offset) {
  55. return $this->get($offset);
  56. }
  57. /**
  58. * @param mixed $offset
  59. * @param mixed $value
  60. */
  61. public function offsetSet($offset, $value): void {
  62. $this->set($offset, $value);
  63. }
  64. /**
  65. * @param mixed $offset
  66. */
  67. public function offsetUnset($offset): void {
  68. $this->remove($offset);
  69. }
  70. /**
  71. * Close the session and release the lock
  72. */
  73. public function close() {
  74. $this->sessionClosed = true;
  75. }
  76. }