use Friendica\App;
use Friendica\BaseObject;
+use Friendica\Core\Cache\ICache;
use Friendica\Core\Session\CacheSessionHandler;
use Friendica\Core\Session\DatabaseSessionHandler;
+use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Util\Strings;
+use Psr\Log\LoggerInterface;
/**
* High-level Session service class
$session_handler = Config::get('system', 'session_handler', 'database');
if ($session_handler != 'native') {
if ($session_handler == 'cache' && Config::get('system', 'cache_driver', 'database') != 'database') {
- $SessionHandler = new CacheSessionHandler();
+ $SessionHandler = new CacheSessionHandler(
+ BaseObject::getClass(ICache::class),
+ BaseObject::getClass(LoggerInterface::class),
+ $_SERVER
+ );
} else {
- $SessionHandler = new DatabaseSessionHandler();
+ $SessionHandler = new DatabaseSessionHandler(
+ BaseObject::getClass(Database::class),
+ BaseObject::getClass(LoggerInterface::class),
+ $_SERVER
+ );
}
session_set_save_handler($SessionHandler);
namespace Friendica\Core\Session;
-use Friendica\BaseObject;
-use Friendica\Core\Cache;
-use Friendica\Core\Logger;
+use Friendica\Core\Cache\ICache;
use Friendica\Core\Session;
+use Psr\Log\LoggerInterface;
use SessionHandlerInterface;
/**
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
+class CacheSessionHandler implements SessionHandlerInterface
{
+ /** @var ICache */
+ private $cache;
+ /** @var LoggerInterface */
+ private $logger;
+ /** @var array The $_SERVER array */
+ private $server;
+
+ /**
+ * CacheSessionHandler constructor.
+ *
+ * @param ICache $cache
+ * @param LoggerInterface $logger
+ * @param array $server
+ */
+ public function __construct(ICache $cache, LoggerInterface $logger, array $server)
+ {
+ $this->cache = $cache;
+ $this->logger = $logger;
+ $this->server = $server;
+ }
+
public function open($save_path, $session_name)
{
return true;
return '';
}
- $data = Cache::get('session:' . $session_id);
+ $data = $this->cache->get('session:' . $session_id);
if (!empty($data)) {
Session::$exists = true;
return $data;
}
- Logger::notice('no data for session', ['session_id' => $session_id, 'uri' => $_SERVER['REQUEST_URI']]);
+ $this->logger->notice('no data for session', ['session_id' => $session_id, 'uri' => $this->server['REQUEST_URI'] ?? '']);
return '';
}
return true;
}
- $return = Cache::set('session:' . $session_id, $session_data, Session::$expire);
-
- return $return;
+ return $this->cache->set('session:' . $session_id, $session_data, Session::$expire);
}
public function close()
public function destroy($id)
{
- $return = Cache::delete('session:' . $id);
-
- return $return;
+ return $this->cache->delete('session:' . $id);
}
public function gc($maxlifetime)
namespace Friendica\Core\Session;
-use Friendica\BaseObject;
-use Friendica\Core\Logger;
use Friendica\Core\Session;
-use Friendica\Database\DBA;
+use Friendica\Database\Database;
+use Psr\Log\LoggerInterface;
use SessionHandlerInterface;
/**
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface
+class DatabaseSessionHandler implements SessionHandlerInterface
{
+ /** @var Database */
+ private $dba;
+ /** @var LoggerInterface */
+ private $logger;
+ /** @var array The $_SERVER variable */
+ private $server;
+
+ /**
+ * DatabaseSessionHandler constructor.
+ *
+ * @param Database $dba
+ * @param LoggerInterface $logger
+ * @param array $server
+ */
+ public function __construct(Database $dba, LoggerInterface $logger, array $server)
+ {
+ $this->dba = $dba;
+ $this->logger = $logger;
+ $this->server = $server;
+ }
+
public function open($save_path, $session_name)
{
return true;
return '';
}
- $session = DBA::selectFirst('session', ['data'], ['sid' => $session_id]);
- if (DBA::isResult($session)) {
+ $session = $this->dba->selectFirst('session', ['data'], ['sid' => $session_id]);
+ if ($this->dba->isResult($session)) {
Session::$exists = true;
return $session['data'];
}
- Logger::notice('no data for session', ['session_id' => $session_id, 'uri' => $_SERVER['REQUEST_URI']]);
+ $this->logger->notice('no data for session', ['session_id' => $session_id, 'uri' => $this->server['REQUEST_URI'] ?? '']);
return '';
}
if (Session::$exists) {
$fields = ['data' => $session_data, 'expire' => $expire];
$condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire];
- DBA::update('session', $fields, $condition);
+ $this->dba->update('session', $fields, $condition);
} else {
$fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data];
- DBA::insert('session', $fields);
+ $this->dba->insert('session', $fields);
}
return true;
public function destroy($id)
{
- DBA::delete('session', ['sid' => $id]);
- return true;
+ return $this->dba->delete('session', ['sid' => $id]);
}
public function gc($maxlifetime)
{
- DBA::delete('session', ["`expire` < ?", time()]);
- return true;
+ return $this->dba->delete('session', ["`expire` < ?", time()]);
}
}
const PATH = '/';
/** @var string The domain name of the Friendica cookie */
const DOMAIN = '';
- /** @var bool True, if the cookie should only be accessable through HTTP */
+ /** @var bool True, if the cookie should only be accessible through HTTP */
const HTTPONLY = true;
/** @var string The remote address of this node */
/**
* Set the Friendica cookie for a user
*
- * @param int $uid The user id
- * @param string $password The user password
- * @param string $privateKey The user private key
- * @param int|null $seconds optional the seconds
+ * @param int $uid The user id
+ * @param string $password The user password
+ * @param string $privateKey The user private key
+ * @param int|null $seconds optional the seconds
*
* @return bool
*/
* @link https://php.net/manual/en/function.setcookie.php
*
* @param string $name
- * @param string $value [optional]
- * @param int $expire [optional]
- * @param bool $secure [optional]
+ * @param string $value [optional]
+ * @param int $expire [optional]
+ * @param bool $secure [optional]
*
* @return bool If output exists prior to calling this function,
*