]> git.mxchange.org Git - friendica.git/commitdiff
Ensure FactorySession->create returns an object no matter what
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 17 Mar 2023 01:12:28 +0000 (21:12 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 19 Mar 2023 03:36:07 +0000 (23:36 -0400)
- Rename redundant method name createSession
- Add exception logging

src/Core/Session/Factory/Session.php
static/dependencies.config.php

index a93cf6631e1e2209722825bdee938a23ccc5a31d..239b050e77723b1abf3473d82b3d71dedde68c48 100644 (file)
@@ -55,19 +55,17 @@ class Session
         * @param LoggerInterface     $logger
         * @param Profiler            $profiler
         * @param array               $server
+        * @return IHandleSessions
         */
-       public function createSession(App\Mode $mode, App\BaseURL $baseURL, IManageConfigValues $config, Database $dba, Cache $cacheFactory, LoggerInterface $logger, Profiler $profiler, array $server = []): IHandleSessions
+       public function create(App\Mode $mode, App\BaseURL $baseURL, IManageConfigValues $config, Database $dba, Cache $cacheFactory, LoggerInterface $logger, Profiler $profiler, array $server = []): IHandleSessions
        {
                $profiler->startRecording('session');
-               $session = null;
+               $session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
 
                try {
                        if ($mode->isInstall() || $mode->isBackend()) {
                                $session = new Type\Memory();
                        } else {
-                               $session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
-                               $handler         = null;
-
                                switch ($session_handler) {
                                        case self::HANDLER_DATABASE:
                                                $handler = new Handler\Database($dba, $logger, $server);
@@ -82,10 +80,15 @@ class Session
                                                        $handler = new Handler\Cache($cache, $logger);
                                                }
                                                break;
+                                       default:
+                                               $handler = null;
                                }
 
                                $session = new Type\Native($baseURL, $handler);
                        }
+               } catch (\Throwable $e) {
+                       $logger->notice('Unable to create session', ['mode' => $mode, 'session_handler' => $session_handler, 'exception' => $e]);
+                       $session = new Type\Memory();
                } finally {
                        $profiler->stopRecording();
                        return $session;
index 42f193ba53e5fcab2bd4e24eb30de783ea033946..0891166424f8bd884a4cdb5f6192a0ab00b1b8c2 100644 (file)
@@ -237,7 +237,7 @@ return [
        IHandleSessions::class => [
                'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
                'call' => [
-                       ['createSession', [$_SERVER], Dice::CHAIN_CALL],
+                       ['create', [$_SERVER], Dice::CHAIN_CALL],
                        ['start', [], Dice::CHAIN_CALL],
                ],
        ],