Conditions | 2 |
Paths | 1 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
46 | private function parseHttpLocale(Request $request): string |
||
47 | { |
||
48 | $list = explode(',', $request->server('HTTP_ACCEPT_LANGUAGE')); |
||
|
|||
49 | |||
50 | $locales = Collection::make($list)->map(function ($locale) { |
||
51 | $parts = explode(';', $locale); |
||
52 | |||
53 | $mapping['locale'] = trim($parts[0]); |
||
54 | |||
55 | if (isset($parts[1])) { |
||
56 | $factorParts = explode('=', $parts[1]); |
||
57 | |||
58 | $mapping['factor'] = $factorParts[1]; |
||
59 | } else { |
||
60 | $mapping['factor'] = 1; |
||
61 | } |
||
62 | |||
63 | return $mapping; |
||
64 | })->sortByDesc(function ($locale) { |
||
65 | return $locale['factor']; |
||
66 | }); |
||
67 | |||
68 | return $locales->first()['locale']; |
||
69 | } |
||
71 |