66
77use Krinkle \Intuition \Intuition as KrinkleIntuition ;
88use Symfony \Component \HttpFoundation \RequestStack ;
9- use Symfony \Component \HttpFoundation \Session \SessionInterface ;
109
1110class Intuition extends KrinkleIntuition
1211{
1312
1413 /**
1514 * @param RequestStack $requestStack
16- * @param SessionInterface $session
1715 * @param string $projectDir Root filesystem directory of the application.
1816 * @param string $domain The i18n domain.
1917 * @return Intuition
2018 */
2119 public static function serviceFactory (
2220 RequestStack $ requestStack ,
23- SessionInterface $ session ,
2421 string $ projectDir ,
2522 string $ domain
2623 ): Intuition {
@@ -29,18 +26,26 @@ public static function serviceFactory(
2926
3027 // Current request doesn't exist in unit tests, in which case we'll fall back to English.
3128 if (null !== $ requestStack ->getCurrentRequest ()) {
32- // Use lang from the request or the session.
33- $ queryLang = $ requestStack ->getCurrentRequest ()->query ->get ('uselang ' );
34- $ sessionLang = $ session ->get ('lang ' );
35- if (!empty ($ queryLang )) {
36- $ useLang = $ queryLang ;
37- } elseif (!empty ($ sessionLang )) {
38- $ 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+ }
3937 }
40-
41- // Save the language to the session.
42- if ($ session ->get ('lang ' ) !== $ useLang ) {
43- $ 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+ }
4449 }
4550 }
4651
0 commit comments