3 namespace Friendica\Factory;
6 use Friendica\Core\Cache\Cache;
7 use Friendica\Core\Cache\ICache;
8 use Friendica\Core\Config\Configuration;
9 use Friendica\Core\Session;
10 use Friendica\Core\System;
11 use Friendica\Database\Database;
12 use Friendica\Model\User\Cookie;
13 use Friendica\Util\Profiler;
14 use Psr\Log\LoggerInterface;
17 * Factory for creating a valid Session for this run
21 /** @var string The plain, PHP internal session management */
22 const HANDLER_NATIVE = 'native';
23 /** @var string Using the database for session management */
24 const HANDLER_DATABASE = 'database';
25 /** @var string Using the cache for session management */
26 const HANDLER_CACHE = 'cache';
28 const HANDLER_DEFAULT = self::HANDLER_DATABASE;
31 * @param App\Mode $mode
32 * @param App\BaseURL $baseURL
33 * @param Configuration $config
34 * @param Cookie $cookie
35 * @param Database $dba
36 * @param ICache $cache
37 * @param LoggerInterface $logger
38 * @param array $server
40 * @return Session\ISession
42 public function createSession(App\Mode $mode, App\BaseURL $baseURL, Configuration $config, Cookie $cookie, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
44 $stamp1 = microtime(true);
48 if ($mode->isInstall() || $mode->isBackend()) {
49 $session = new Session\Memory($cookie);
51 $session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
54 switch ($session_handler) {
55 case self::HANDLER_DATABASE:
56 $handler = new Session\Handler\Database($dba, $logger, $server);
58 case self::HANDLER_CACHE:
59 // In case we're using the db as cache driver, use the native db session, not the cache
60 if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
61 $handler = new Session\Handler\Database($dba, $logger, $server);
63 $handler = new Session\Handler\Cache($cache, $logger, $server);
68 $session = new Session\Native($baseURL, $cookie, $handler);
71 $profiler->saveTimestamp($stamp1, 'parser', System::callstack());