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 INTERNAL = 'native';
23 /** @var string Using the database for session management */
24 const DATABASE = 'database';
25 /** @var string Using the cache for session management */
26 const CACHE = 'cache';
27 /** @var string A temporary cached session */
28 const MEMORY = 'memory';
29 /** @var string The default type for Session management in case of no config */
30 const DEFAULT = self::DATABASE;
33 * @param App\Mode $mode
34 * @param Configuration $config
35 * @param Cookie $cookie
36 * @param Database $dba
37 * @param ICache $cache
38 * @param LoggerInterface $logger
39 * @param array $server
41 * @return Session\ISession
43 public function createSession(App\Mode $mode, Configuration $config, Cookie $cookie, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
45 $stamp1 = microtime(true);
49 if ($mode->isInstall() || $mode->isBackend()) {
50 $session = new Session\Memory($config, $cookie);
52 $session_handler = $config->get('system', 'session_handler', self::DEFAULT);
54 switch ($session_handler) {
56 $session = new Session\Native($config, $cookie);
60 $session = new Session\Database($config, $cookie, $dba, $logger, $server);
63 // In case we're using the db as cache driver, use the native db session, not the cache
64 if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
65 $session = new Session\Database($config, $cookie, $dba, $logger, $server);
67 $session = new Session\Cache($config, $cookie, $cache, $logger, $server);
73 $profiler->saveTimestamp($stamp1, 'parser', System::callstack());