1 | <?php |
||
14 | class LanguageNegotiator |
||
15 | { |
||
16 | use Utils\NegotiateTrait; |
||
17 | use Utils\BasePathTrait; |
||
18 | use Utils\RedirectTrait; |
||
19 | |||
20 | const KEY = 'LANGUAGE'; |
||
21 | |||
22 | /** |
||
23 | * @var array Allowed languages |
||
24 | */ |
||
25 | private $languages = []; |
||
26 | |||
27 | /** |
||
28 | * @var bool Use the path to detect the language |
||
29 | */ |
||
30 | private $usePath = false; |
||
31 | |||
32 | /** |
||
33 | * Returns the language. |
||
34 | * |
||
35 | * @param ServerRequestInterface $request |
||
36 | * |
||
37 | * @return string|null |
||
38 | */ |
||
39 | public static function getLanguage(ServerRequestInterface $request) |
||
43 | |||
44 | /** |
||
45 | * Define de available languages. |
||
46 | * |
||
47 | * @param array $languages |
||
48 | */ |
||
49 | public function __construct(array $languages) |
||
53 | |||
54 | /** |
||
55 | * Use the base path to detect the current language. |
||
56 | * |
||
57 | * @param bool $usePath |
||
58 | * |
||
59 | * @return self |
||
60 | */ |
||
61 | public function usePath($usePath = true) |
||
67 | |||
68 | /** |
||
69 | * Execute the middleware. |
||
70 | * |
||
71 | * @param ServerRequestInterface $request |
||
72 | * @param ResponseInterface $response |
||
73 | * @param callable $next |
||
74 | * |
||
75 | * @return ResponseInterface |
||
76 | */ |
||
77 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
117 | } |
||
118 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: