From: nupplaPhil Date: Tue, 10 Dec 2019 21:29:49 +0000 (+0100) Subject: Use Native Session functions (global "$_SESSION" variable) for Memory class because... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b9f8762eb3b4f125dcdf5335cd992466b79a5ef6;p=friendica.git Use Native Session functions (global "$_SESSION" variable) for Memory class because of the direct usage of the $_SESSION class all around the codebase --- diff --git a/src/Core/Session/Database.php b/src/Core/Session/Database.php index 5874c5d4f5..1051100229 100644 --- a/src/Core/Session/Database.php +++ b/src/Core/Session/Database.php @@ -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); diff --git a/src/Core/Session/Memory.php b/src/Core/Session/Memory.php index a7e336627f..b39234db23 100644 --- a/src/Core/Session/Memory.php +++ b/src/Core/Session/Memory.php @@ -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; - } -} \ No newline at end of file +} diff --git a/src/Factory/SessionFactory.php b/src/Factory/SessionFactory.php index e87f8bd2b6..f4268a2b95 100644 --- a/src/Factory/SessionFactory.php +++ b/src/Factory/SessionFactory.php @@ -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); diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 245529fb21..1419f7d7fe 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -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,