Conditions | 4 |
Paths | 4 |
Total Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
11 | public function handle($request, Closure $next, $segment = 0) |
||
12 | { |
||
13 | // Ignores all non GET requests: |
||
14 | if ('GET' !== $request->method()) { |
||
15 | return $next($request); |
||
16 | } |
||
17 | |||
18 | $currentUrl = $request->getUri(); |
||
19 | $uriLocale = Localize::getLocaleFromUrl($currentUrl, $segment); |
||
20 | $defaultLocale = config('presspack.default_locale'); |
||
21 | // If a locale was set in the url: |
||
22 | if ($uriLocale) { |
||
23 | // Set app locale |
||
24 | App::setLocale($uriLocale); |
||
25 | |||
26 | return $next($request); |
||
27 | } |
||
28 | |||
29 | // If no locale was set in the url, check the browser's locale: |
||
30 | $browserLocale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2); |
||
31 | if (Localize::isValidLocale($browserLocale)) { |
||
32 | return redirect()->to(Localize::url($currentUrl, $browserLocale, $segment)); |
||
33 | } |
||
34 | |||
35 | // If not, redirect to the default locale: |
||
36 | |||
37 | return redirect()->to(Localize::url($currentUrl, $defaultLocale, $segment)); |
||
38 | } |
||
39 | } |
||
40 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: