1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Nexendrie\Translation\Bridges\NetteApplication; |
||
5 | |||
6 | use Nette\Application\Application; |
||
7 | use Nette\Application\Request; |
||
8 | |||
9 | /** |
||
10 | * ParamLocaleResolver |
||
11 | * |
||
12 | * @author Jakub Konečný |
||
13 | */ |
||
14 | final class ParamLocaleResolver implements IAppRequestAwareLocaleResolver { |
||
15 | use \Nette\SmartObject; |
||
16 | |||
17 | private ?Request $request = null; |
||
18 | /** @var string */ |
||
19 | public string $param = "locale"; |
||
20 | |||
21 | /** |
||
22 | * @deprecated Access the property directly |
||
23 | */ |
||
24 | public function getParam(): string { |
||
25 | return $this->param; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @deprecated Access the property directly |
||
30 | */ |
||
31 | public function setParam(string $param): void { |
||
32 | $this->param = $param; |
||
33 | } |
||
34 | |||
35 | public function onRequest(Application $application, Request $request): void { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
36 | 1 | $locale = $request->getParameter($this->param); |
|
37 | 1 | if($request->method === Request::FORWARD && $locale === null) { |
|
38 | return; |
||
39 | } |
||
40 | 1 | $this->request = $request; |
|
41 | 1 | } |
|
42 | |||
43 | public function resolve(): ?string { |
||
44 | 1 | if($this->request !== null) { |
|
45 | 1 | return $this->request->getParameter($this->param); |
|
46 | } |
||
47 | 1 | return null; |
|
48 | } |
||
49 | } |
||
50 | ?> |