use Friendica\Core\Config\Configuration;
use Friendica\Core\Session;
-use Friendica\Database\Database;
+use Friendica\Database\Database as DBA;
use Friendica\Model\User\Cookie;
use Psr\Log\LoggerInterface;
use SessionHandlerInterface;
*/
final class Database extends Native implements SessionHandlerInterface
{
- /** @var Database */
+ /** @var DBA */
private $dba;
/** @var LoggerInterface */
private $logger;
* @param LoggerInterface $logger
* @param array $server
*/
- public function __construct(Configuration $config, Cookie $cookie, Database $dba, LoggerInterface $logger, array $server)
+ public function __construct(Configuration $config, Cookie $cookie, DBA $dba, LoggerInterface $logger, array $server)
{
parent::__construct($config, $cookie);
/**
* Usable for backend processes (daemon/worker) and testing
+ *
+ * @todo after replacing the last direct $_SESSION call, use a internal array instead of the global variable
*/
-final class Memory implements ISession
+final class Memory extends Native
{
- private $data = [];
-
public function start()
{
// Backward compatibility until all Session variables are replaced
$this->clear();
return $this;
}
-
- /**
- * @inheritDoc
- */
- public function exists(string $name)
- {
- return isset($this->data[$name]);
- }
-
- /**
- * @inheritDoc
- */
- public function get(string $name, $defaults = null)
- {
- return $this->data[$name] ?? $defaults;
- }
-
- /**
- * @inheritDoc
- */
- public function set(string $name, $value)
- {
- $this->data[$name] = $value;
- }
-
- /**
- * @inheritDoc
- */
- public function setMultiple(array $values)
- {
- foreach ($values as $key => $value) {
- $this->data[$key] = $value;
- }
- }
-
- /**
- * @inheritDoc
- */
- public function remove(string $name)
- {
- if ($this->exists($name)) {
- unset($this->data[$name]);
- return true;
- }
-
- return false;
- }
-
- /**
- * @inheritDoc
- */
- public function clear()
- {
- $this->data = [];
- return true;
- }
-
- /**
- * @inheritDoc
- */
- public function delete()
- {
- $this->data = [];
- return true;
- }
-}
\ No newline at end of file
+}
try {
if ($mode->isInstall() || $mode->isBackend()) {
- $session = new Session\Memory();
+ $session = new Session\Memory($config, $cookie);
} else {
$session_handler = $config->get('system', 'session_handler', self::DEFAULT);
use Friendica\Core\Config\Configuration;
use Friendica\Core\Config\PConfiguration;
use Friendica\Core\Protocol;
+use Friendica\Core\Session\ISession;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Network\HTTPException;
// User ID that we know is not in the database
$this->wrongUserId = 666;
+ /** @var ISession $session */
+ $session = BaseObject::getClass(ISession::class);
+ $session->start();
+
// Most API require login so we force the session
$_SESSION = [
'allow_api' => true,