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\CacheSession;
10 use Friendica\Core\Session\DatabaseSession;
11 use Friendica\Core\Session\ISession;
12 use Friendica\Core\Session\Memory;
13 use Friendica\Core\Session\MemorySession;
14 use Friendica\Core\Session\NativeSession;
15 use Friendica\Core\System;
16 use Friendica\Database\Database;
17 use Friendica\Model\User\Cookie;
18 use Friendica\Util\Profiler;
19 use Psr\Log\LoggerInterface;
22 * Factory for creating a valid Session for this run
26 /** @var string The plain, PHP internal session management */
27 const INTERNAL = 'native';
28 /** @var string Using the database for session management */
29 const DATABASE = 'database';
30 /** @var string Using the cache for session management */
31 const CACHE = 'cache';
32 /** @var string A temporary cached session */
33 const MEMORY = 'memory';
34 /** @var string The default type for Session management in case of no config */
35 const DEFAULT = self::DATABASE;
38 * @param App\Mode $mode
39 * @param Configuration $config
40 * @param Cookie $cookie
41 * @param Database $dba
42 * @param ICache $cache
43 * @param LoggerInterface $logger
44 * @param array $server
48 public function createSession(App\Mode $mode, Configuration $config, Cookie $cookie, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
50 $stamp1 = microtime(true);
54 if ($mode->isInstall() || $mode->isBackend()) {
55 $session = new MemorySession();
57 $session_handler = $config->get('system', 'session_handler', self::DEFAULT);
59 switch ($session_handler) {
61 $session = new NativeSession($config, $cookie);
65 $session = new DatabaseSession($config, $cookie, $dba, $logger, $server);
68 // In case we're using the db as cache driver, use the native db session, not the cache
69 if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
70 $session = new DatabaseSession($config, $cookie, $dba, $logger, $server);
72 $session = new CacheSession($config, $cookie, $cache, $logger, $server);
78 $profiler->saveTimestamp($stamp1, 'parser', System::callstack());