Merge pull request #12898 from MrPetovan/bug/12792-createSession-return
Ensure FactorySession->create returns an object no matter what
This commit is contained in:
commit
b8eea3f1d8
3 changed files with 10 additions and 7 deletions
|
@ -55,19 +55,17 @@ class Session
|
||||||
* @param LoggerInterface $logger
|
* @param LoggerInterface $logger
|
||||||
* @param Profiler $profiler
|
* @param Profiler $profiler
|
||||||
* @param array $server
|
* @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');
|
$profiler->startRecording('session');
|
||||||
$session = null;
|
$session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($mode->isInstall() || $mode->isBackend()) {
|
if ($mode->isInstall() || $mode->isBackend()) {
|
||||||
$session = new Type\Memory();
|
$session = new Type\Memory();
|
||||||
} else {
|
} else {
|
||||||
$session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
|
|
||||||
$handler = null;
|
|
||||||
|
|
||||||
switch ($session_handler) {
|
switch ($session_handler) {
|
||||||
case self::HANDLER_DATABASE:
|
case self::HANDLER_DATABASE:
|
||||||
$handler = new Handler\Database($dba, $logger, $server);
|
$handler = new Handler\Database($dba, $logger, $server);
|
||||||
|
@ -82,10 +80,15 @@ class Session
|
||||||
$handler = new Handler\Cache($cache, $logger);
|
$handler = new Handler\Cache($cache, $logger);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
$handler = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$session = new Type\Native($baseURL, $handler);
|
$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 {
|
} finally {
|
||||||
$profiler->stopRecording();
|
$profiler->stopRecording();
|
||||||
return $session;
|
return $session;
|
||||||
|
|
|
@ -237,7 +237,7 @@ return [
|
||||||
IHandleSessions::class => [
|
IHandleSessions::class => [
|
||||||
'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
|
'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createSession', [$_SERVER], Dice::CHAIN_CALL],
|
['create', [$_SERVER], Dice::CHAIN_CALL],
|
||||||
['start', [], Dice::CHAIN_CALL],
|
['start', [], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -80,6 +80,6 @@ class DBKeyValueStorageTest extends KeyValueStorageTest
|
||||||
|
|
||||||
$updateAtAfter = $entry['updated_at'];
|
$updateAtAfter = $entry['updated_at'];
|
||||||
|
|
||||||
self::assertLessThanOrEqual($updateAt, $updateAtAfter);
|
self::assertGreaterThanOrEqual($updateAt, $updateAtAfter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue