Completed
Branch master (e25020)
by Richan
03:06
created

NegotiateLanguage::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace RichanFongdasen\I18n\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class NegotiateLanguage
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param \Illuminate\Http\Request $request
14
     * @param \Closure                 $next
15
     *
16
     * @return mixed
17
     */
18
    public function handle(Request $request, Closure $next)
19
    {
20
        if (\I18n::routedLocale($request) === null) {
21
            $negotiator = \I18n::getConfig('negotiator');
22
            $locale = app($negotiator)->preferredLocale($request);
23
24
            return redirect(\I18n::url($request->getRequestUri(), $locale));
25
        }
26
27
        return $next($request);
28
    }
29
}
30