]> git.mxchange.org Git - friendica.git/blobdiff - src/Factory/SessionFactory.php
Create constants for Mastodon notification types
[friendica.git] / src / Factory / SessionFactory.php
index f2bfd10d4ede64be3ba66ff1e77ab83b2bddfb84..491573033bd4b22994ddda1ce06381d47be5f199 100644 (file)
@@ -1,17 +1,33 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Factory;
 
 use Friendica\App;
-use Friendica\Core\Cache\Cache;
 use Friendica\Core\Cache\ICache;
-use Friendica\Core\Config\Configuration;
-use Friendica\Core\Session\ISession;
-use Friendica\Core\Session\Memory;
-use Friendica\Core\Session\Native;
+use Friendica\Core\Cache\Type;
+use Friendica\Core\Config\IConfig;
+use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Database\Database;
-use Friendica\Model\User\Cookie;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 
@@ -21,58 +37,55 @@ use Psr\Log\LoggerInterface;
 class SessionFactory
 {
        /** @var string The plain, PHP internal session management */
-       const INTERNAL = 'native';
+       const HANDLER_NATIVE = 'native';
        /** @var string Using the database for session management */
-       const DATABASE = 'database';
+       const HANDLER_DATABASE = 'database';
        /** @var string Using the cache for session management */
-       const CACHE = 'cache';
-       /** @var string A temporary cached session */
-       const MEMORY  = 'memory';
-       /** @var string The default type for Session management in case of no config */
-       const DEFAULT = self::DATABASE;
+       const HANDLER_CACHE = 'cache';
+
+       const HANDLER_DEFAULT = self::HANDLER_DATABASE;
 
        /**
         * @param App\Mode        $mode
-        * @param Configuration   $config
-        * @param Cookie          $cookie
+        * @param App\BaseURL     $baseURL
+        * @param IConfig         $config
         * @param Database        $dba
         * @param ICache          $cache
         * @param LoggerInterface $logger
         * @param array           $server
         *
-        * @return ISession
+        * @return Session\ISession
         */
-       public function createSession(App\Mode $mode, Configuration $config, Cookie $cookie, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
+       public function createSession(App\Mode $mode, App\BaseURL $baseURL, IConfig $config, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = [])
        {
-               $stamp1  = microtime(true);
+               $profiler->startRecording('session');
                $session = null;
 
                try {
                        if ($mode->isInstall() || $mode->isBackend()) {
-                               $session = new Memory();
+                               $session = new Session\Memory();
                        } else {
-                               $session_handler = $config->get('system', 'session_handler', self::DEFAULT);
+                               $session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
+                               $handler = null;
 
                                switch ($session_handler) {
-                                       case self::INTERNAL:
-                                               $session = new Native($config, $cookie);
+                                       case self::HANDLER_DATABASE:
+                                               $handler = new Session\Handler\Database($dba, $logger, $server);
                                                break;
-                                       case self::DATABASE:
-                                       default:
-                                               $session = new Database($config, $cookie, $dba, $logger, $server);
-                                               break;
-                                       case self::CACHE:
+                                       case self::HANDLER_CACHE:
                                                // In case we're using the db as cache driver, use the native db session, not the cache
-                                               if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
-                                                       $session = new Database($config, $cookie, $dba, $logger, $server);
+                                               if ($config->get('system', 'cache_driver') === Type::DATABASE) {
+                                                       $handler = new Session\Handler\Database($dba, $logger, $server);
                                                } else {
-                                                       $session = new Cache($config, $cookie, $cache, $logger, $server);
+                                                       $handler = new Session\Handler\Cache($cache);
                                                }
                                                break;
                                }
+
+                               $session = new Session\Native($baseURL, $handler);
                        }
                } finally {
-                       $profiler->saveTimestamp($stamp1, 'parser', System::callstack());
+                       $profiler->stopRecording();
                        return $session;
                }
        }