1 | <?php |
||
13 | class LanguageNegotiator |
||
14 | { |
||
15 | use Utils\NegotiateTrait; |
||
16 | use Utils\RedirectTrait; |
||
17 | use Utils\AttributeTrait; |
||
18 | |||
19 | const KEY = 'LANGUAGE'; |
||
20 | |||
21 | /** |
||
22 | * @var array Allowed languages |
||
23 | */ |
||
24 | private $languages = []; |
||
25 | |||
26 | /** |
||
27 | * @var bool Use the path to detect the language |
||
28 | */ |
||
29 | private $usePath = false; |
||
30 | |||
31 | /** |
||
32 | * Returns the language. |
||
33 | * |
||
34 | * @param ServerRequestInterface $request |
||
35 | * |
||
36 | * @return string|null |
||
37 | */ |
||
38 | public static function getLanguage(ServerRequestInterface $request) |
||
42 | |||
43 | /** |
||
44 | * Define de available languages. |
||
45 | * |
||
46 | * @param array $languages |
||
47 | */ |
||
48 | public function __construct(array $languages) |
||
52 | |||
53 | /** |
||
54 | * Use the base path to detect the current language. |
||
55 | * |
||
56 | * @param bool $usePath |
||
57 | * |
||
58 | * @return self |
||
59 | */ |
||
60 | public function usePath($usePath = true) |
||
66 | |||
67 | /** |
||
68 | * Execute the middleware. |
||
69 | * |
||
70 | * @param ServerRequestInterface $request |
||
71 | * @param ResponseInterface $response |
||
72 | * @param callable $next |
||
73 | * |
||
74 | * @return ResponseInterface |
||
75 | */ |
||
76 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
122 | } |
||
123 |