Skip to content

Commit dcb795f

Browse files
committed
More checking for session before using
1 parent b9b0a85 commit dcb795f

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

Service/Intuition.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,26 @@ public static function serviceFactory(
2626

2727
// Current request doesn't exist in unit tests, in which case we'll fall back to English.
2828
if (null !== $requestStack->getCurrentRequest()) {
29-
// Use lang from the request or the session.
30-
$queryLang = $requestStack->getCurrentRequest()->query->get('uselang');
31-
$session = $requestStack->getSession();
32-
$sessionLang = $session->get('lang');
33-
if (!empty($queryLang)) {
34-
$useLang = $queryLang;
35-
} elseif (!empty($sessionLang)) {
36-
$useLang = $sessionLang;
29+
$currentRequest = $requestStack->getCurrentRequest();
30+
// Use lang from the 'lang' query parameter or the 'lang' session variable.
31+
$queryLang = false;
32+
if ($currentRequest->query->has('uselang')) {
33+
$queryLang = $currentRequest->query->has('uselang');
34+
if (!empty($queryLang)) {
35+
$useLang = $queryLang;
36+
}
3737
}
38-
39-
// Save the language to the session.
40-
if ($session->get('lang') !== $useLang) {
41-
$session->set('lang', $useLang);
38+
$sessionLang = false;
39+
if ($currentRequest->hasSession()) {
40+
$session = $currentRequest->getSession();
41+
$sessionLang = $session->get('lang');
42+
if (!empty($sessionLang)) {
43+
$useLang = $sessionLang;
44+
}
45+
// Save the language to the session.
46+
if ($session->get('lang') !== $useLang) {
47+
$session->set('lang', $useLang);
48+
}
4249
}
4350
}
4451

Twig/Extension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function getFunctions(): array
7171
*/
7272
public function getLoggedInUser()
7373
{
74+
if (!$this->session) {
75+
return false;
76+
}
7477
return $this->session->get('logged_in_user');
7578
}
7679

0 commit comments

Comments
 (0)