Use Native Session functions (global "$_SESSION" variable) for Memory class because of the direct usage of the $_SESSION class all around the codebase
This commit is contained in:
parent
eca3396851
commit
b9f8762eb3
|
@ -4,7 +4,7 @@ namespace Friendica\Core\Session;
|
|||
|
||||
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;
|
||||
|
@ -16,7 +16,7 @@ use SessionHandlerInterface;
|
|||
*/
|
||||
final class Database extends Native implements SessionHandlerInterface
|
||||
{
|
||||
/** @var Database */
|
||||
/** @var DBA */
|
||||
private $dba;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
@ -30,7 +30,7 @@ final class Database extends Native implements SessionHandlerInterface
|
|||
* @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);
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ namespace Friendica\Core\Session;
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
@ -17,69 +17,4 @@ final class Memory implements ISession
|
|||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class SessionFactory
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use Friendica\BaseObject;
|
|||
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;
|
||||
|
@ -111,6 +112,10 @@ class ApiTest extends DatabaseTest
|
|||
// 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,
|
||||
|
|
Loading…
Reference in a new issue