You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 11 години
преди 11 години
преди 8 години
преди 9 години
преди 8 години
преди 9 години
преди 8 години
преди 9 години
преди 9 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Session;
  30. use OCP\Session\Exceptions\SessionNotAvailableException;
  31. /**
  32. * Class Internal
  33. *
  34. * store session data in an in-memory array, not persistent
  35. *
  36. * @package OC\Session
  37. */
  38. class Memory extends Session {
  39. protected $data;
  40. public function __construct(string $name) {
  41. //no need to use $name since all data is already scoped to this instance
  42. $this->data = [];
  43. }
  44. /**
  45. * @param string $key
  46. * @param integer $value
  47. */
  48. public function set(string $key, $value) {
  49. $this->data[$key] = $value;
  50. }
  51. /**
  52. * @param string $key
  53. * @return mixed
  54. */
  55. public function get(string $key) {
  56. if (!$this->exists($key)) {
  57. return null;
  58. }
  59. return $this->data[$key];
  60. }
  61. /**
  62. * @param string $key
  63. * @return bool
  64. */
  65. public function exists(string $key): bool {
  66. return isset($this->data[$key]);
  67. }
  68. /**
  69. * @param string $key
  70. */
  71. public function remove(string $key) {
  72. unset($this->data[$key]);
  73. }
  74. public function clear() {
  75. $this->data = [];
  76. }
  77. /**
  78. * Stub since the session ID does not need to get regenerated for the cache
  79. *
  80. * @param bool $deleteOldSession
  81. */
  82. public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false) {
  83. }
  84. /**
  85. * Wrapper around session_id
  86. *
  87. * @return string
  88. * @throws SessionNotAvailableException
  89. * @since 9.1.0
  90. */
  91. public function getId(): string {
  92. throw new SessionNotAvailableException('Memory session does not have an ID');
  93. }
  94. /**
  95. * Helper function for PHPUnit execution - don't use in non-test code
  96. */
  97. public function reopen(): bool {
  98. $reopened = $this->sessionClosed;
  99. $this->sessionClosed = false;
  100. return $reopened;
  101. }
  102. }