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\Util\Profiler;
13 use Psr\Log\LoggerInterface;
16 * Factory for creating a valid Session for this run
20 /** @var string The plain, PHP internal session management */
21 const HANDLER_NATIVE = 'native';
22 /** @var string Using the database for session management */
23 const HANDLER_DATABASE = 'database';
24 /** @var string Using the cache for session management */
25 const HANDLER_CACHE = 'cache';
27 const HANDLER_DEFAULT = self::HANDLER_DATABASE;
30 * @param App\Mode $mode
31 * @param App\BaseURL $baseURL
32 * @param Configuration $config
33 * @param Database $dba
34 * @param ICache $cache
35 * @param LoggerInterface $logger
36 * @param array $server
38 * @return Session\ISession
40 public function createSession(App\Mode $mode, App\BaseURL $baseURL, Configuration $config, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
42 $stamp1 = microtime(true);
46 if ($mode->isInstall() || $mode->isBackend()) {
47 $session = new Session\Memory();
49 $session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
52 switch ($session_handler) {
53 case self::HANDLER_DATABASE:
54 $handler = new Session\Handler\Database($dba, $logger, $server);
56 case self::HANDLER_CACHE:
57 // In case we're using the db as cache driver, use the native db session, not the cache
58 if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
59 $handler = new Session\Handler\Database($dba, $logger, $server);
61 $handler = new Session\Handler\Cache($cache, $logger, $server);
66 $session = new Session\Native($baseURL, $handler);
69 $profiler->saveTimestamp($stamp1, 'parser', System::callstack());