2013-05-27 18:50:00 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-02-26 16:20:21 -05:00
|
|
|
declare(strict_types=1);
|
2013-05-27 18:50:00 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-05-27 18:50:00 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Session;
|
|
|
|
|
|
2016-04-26 03:29:15 -04:00
|
|
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
|
|
|
|
|
2013-05-27 18:50:00 -04:00
|
|
|
/**
|
|
|
|
|
* Class Internal
|
|
|
|
|
*
|
2013-12-09 06:38:27 -05:00
|
|
|
* store session data in an in-memory array, not persistent
|
2013-05-27 18:50:00 -04:00
|
|
|
*
|
|
|
|
|
* @package OC\Session
|
|
|
|
|
*/
|
2013-05-28 10:52:40 -04:00
|
|
|
class Memory extends Session {
|
2013-05-27 18:50:00 -04:00
|
|
|
protected $data;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $key
|
2014-02-06 10:30:58 -05:00
|
|
|
* @param integer $value
|
2013-05-27 18:50:00 -04:00
|
|
|
*/
|
2018-02-26 16:20:21 -05:00
|
|
|
public function set(string $key, $value) {
|
2013-05-27 18:50:00 -04:00
|
|
|
$this->data[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2018-02-26 16:20:21 -05:00
|
|
|
public function get(string $key) {
|
2013-05-27 18:50:00 -04:00
|
|
|
if (!$this->exists($key)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return $this->data[$key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2018-02-26 16:20:21 -05:00
|
|
|
public function exists(string $key): bool {
|
2013-05-27 18:50:00 -04:00
|
|
|
return isset($this->data[$key]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $key
|
|
|
|
|
*/
|
2018-02-26 16:20:21 -05:00
|
|
|
public function remove(string $key) {
|
2013-05-27 18:50:00 -04:00
|
|
|
unset($this->data[$key]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function clear() {
|
2018-02-26 16:20:21 -05:00
|
|
|
$this->data = [];
|
2013-05-27 18:50:00 -04:00
|
|
|
}
|
2014-03-10 09:21:12 -04:00
|
|
|
|
2016-01-04 09:00:58 -05:00
|
|
|
/**
|
|
|
|
|
* Stub since the session ID does not need to get regenerated for the cache
|
|
|
|
|
*
|
|
|
|
|
* @param bool $deleteOldSession
|
|
|
|
|
*/
|
2020-04-10 08:19:56 -04:00
|
|
|
public function regenerateId(bool $deleteOldSession = true, bool $updateToken = false) {
|
|
|
|
|
}
|
2016-01-04 09:00:58 -05:00
|
|
|
|
2016-04-25 04:23:06 -04:00
|
|
|
/**
|
|
|
|
|
* Wrapper around session_id
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2016-04-26 03:29:15 -04:00
|
|
|
* @throws SessionNotAvailableException
|
2016-04-25 04:23:06 -04:00
|
|
|
* @since 9.1.0
|
|
|
|
|
*/
|
2018-02-26 16:20:21 -05:00
|
|
|
public function getId(): string {
|
2016-04-26 03:29:15 -04:00
|
|
|
throw new SessionNotAvailableException('Memory session does not have an ID');
|
2016-04-25 04:23:06 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-17 16:57:10 -04:00
|
|
|
/**
|
|
|
|
|
* Helper function for PHPUnit execution - don't use in non-test code
|
|
|
|
|
*/
|
2022-04-26 06:57:58 -04:00
|
|
|
public function reopen(): bool {
|
|
|
|
|
$reopened = $this->sessionClosed;
|
2014-03-17 16:57:10 -04:00
|
|
|
$this->sessionClosed = false;
|
2022-04-26 06:57:58 -04:00
|
|
|
return $reopened;
|
2014-03-17 16:57:10 -04:00
|
|
|
}
|
2013-05-27 18:50:00 -04:00
|
|
|
}
|