Conditions | 5 |
Paths | 7 |
Total Lines | 28 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
40 | public function handle(Request $request, Closure $next) |
||
41 | { |
||
42 | $session = $request->getSession(); |
||
43 | |||
44 | if (null !== $session) { |
||
45 | if (true === $session->has(self::SESSION_KEY)) { |
||
46 | $session->put(self::SESSION_KEY, $request->getPreferredLanguage(self::LOCALES)); |
||
47 | } |
||
48 | |||
49 | if (true === $request->has('lang')) { |
||
50 | $lang = $request->get('lang'); |
||
51 | $locales = (array) $this->languageRepository->getLocales(); |
||
52 | |||
53 | if (true === in_array($lang, $locales)) { |
||
54 | $session->put(self::SESSION_KEY, $lang); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | app()->setLocale($session->get(self::SESSION_KEY)); |
||
59 | |||
60 | return $next($request); |
||
61 | } |
||
62 | |||
63 | $lang = $request->server('HTTP_ACCEPT_LANGUAGE'); |
||
64 | |||
65 | app()->setLocale($lang); |
||
66 | |||
67 | return $next($request); |
||
68 | } |
||
70 |