1 | <?php |
||||
2 | |||||
3 | namespace Gameap\Http\Middleware; |
||||
4 | |||||
5 | use Illuminate\Http\Request; |
||||
6 | use Closure; |
||||
7 | |||||
8 | class PreferLanguageMiddleware |
||||
9 | { |
||||
10 | public function handle(Request $request, Closure $next) |
||||
11 | { |
||||
12 | if (!extension_loaded('intl') || app()->getLocale() != '') { |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
13 | return $next($request); |
||||
14 | } |
||||
15 | |||||
16 | $headerValue = $request->server('HTTP_ACCEPT_LANGUAGE'); |
||||
17 | if ($headerValue !== null && !is_array($headerValue) && $headerValue !== "") { |
||||
18 | $locale = \Locale::acceptFromHttp($headerValue); |
||||
19 | |||||
20 | if ($locale !== false && $locale !== "") { |
||||
21 | $locale = substr($locale, 0, 2); |
||||
22 | app()->setLocale($locale); |
||||
0 ignored issues
–
show
The method
setLocale() does not exist on Illuminate\Container\Container . Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
23 | } |
||||
24 | } |
||||
25 | |||||
26 | |||||
27 | return $next($request); |
||||
28 | } |
||||
29 | } |
||||
30 |