These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Nexendrie\Translation\Bridges\NetteApplication; |
||
5 | |||
6 | use Nette\Application\Application, |
||
7 | Nette\Application\Request; |
||
8 | |||
9 | /** |
||
10 | * ParamLocaleResolver |
||
11 | * |
||
12 | * @author Jakub Konečný |
||
13 | * @property string $param |
||
14 | */ |
||
15 | 1 | class ParamLocaleResolver implements IAppRequestAwareLocaleResolver { |
|
16 | 1 | use \Nette\SmartObject; |
|
17 | |||
18 | /** @var Request */ |
||
19 | protected $request; |
||
20 | /** @var string */ |
||
21 | protected $param = "locale"; |
||
22 | |||
23 | public function getParam(): string { |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
24 | 1 | return $this->param; |
|
25 | } |
||
26 | |||
27 | public function setParam(string $param) { |
||
28 | 1 | $this->param = $param; |
|
29 | 1 | } |
|
30 | |||
31 | public function onRequest(Application $application, Request $request): void { |
||
32 | 1 | $locale = $request->getParameter($this->param); |
|
33 | 1 | if($request->method === Request::FORWARD AND is_null($locale)) { |
|
34 | return; |
||
35 | } |
||
36 | 1 | $this->request = $request; |
|
37 | 1 | } |
|
38 | |||
39 | /** |
||
40 | * Resolve language |
||
41 | */ |
||
42 | public function resolve(): ?string { |
||
0 ignored issues
–
show
|
|||
43 | 1 | if(!is_null($this->request)) { |
|
44 | 1 | return $this->request->getParameter($this->param); |
|
45 | } |
||
46 | 1 | return NULL; |
|
47 | } |
||
48 | } |
||
49 | ?> |