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\ISession;
10 use Friendica\Core\Session\Memory;
11 use Friendica\Core\Session\Native;
12 use Friendica\Core\System;
13 use Friendica\Database\Database;
14 use Friendica\Model\User\Cookie;
15 use Friendica\Util\Profiler;
16 use Psr\Log\LoggerInterface;
19 * Factory for creating a valid Session for this run
23 /** @var string The plain, PHP internal session management */
24 const INTERNAL = 'native';
25 /** @var string Using the database for session management */
26 const DATABASE = 'database';
27 /** @var string Using the cache for session management */
28 const CACHE = 'cache';
29 /** @var string A temporary cached session */
30 const MEMORY = 'memory';
31 /** @var string The default type for Session management in case of no config */
32 const DEFAULT = self::DATABASE;
35 * @param App\Mode $mode
36 * @param Configuration $config
37 * @param Cookie $cookie
38 * @param Database $dba
39 * @param ICache $cache
40 * @param LoggerInterface $logger
41 * @param array $server
45 public function createSession(App\Mode $mode, Configuration $config, Cookie $cookie, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
47 $stamp1 = microtime(true);
51 if ($mode->isInstall() || $mode->isBackend()) {
52 $session = new Memory();
54 $session_handler = $config->get('system', 'session_handler', self::DEFAULT);
56 switch ($session_handler) {
58 $session = new Native($config, $cookie);
62 $session = new Database($config, $cookie, $dba, $logger, $server);
65 // In case we're using the db as cache driver, use the native db session, not the cache
66 if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
67 $session = new Database($config, $cookie, $dba, $logger, $server);
69 $session = new Cache($config, $cookie, $cache, $logger, $server);
75 $profiler->saveTimestamp($stamp1, 'parser', System::callstack());