Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
23 | final readonly class CookieLocaleResolver implements LocaleResolver |
||
1 ignored issue
–
show
|
|||
24 | { |
||
25 | public function __construct( |
||
26 | protected string $parameterName, |
||
27 | protected Request $httpRequest, |
||
28 | protected Response $httpResponse, |
||
29 | ) {} |
||
30 | |||
31 | /** |
||
32 | * @param string[] $allowed |
||
33 | */ |
||
34 | #[\Override] |
||
35 | public function resolve(array $allowed): ?string |
||
36 | { |
||
37 | return $this->httpRequest->getCookie($this->parameterName); |
||
38 | } |
||
39 | |||
40 | public function set(string $lang): bool |
||
41 | { |
||
42 | try { |
||
43 | $this->httpResponse->setCookie( |
||
44 | $this->parameterName, |
||
45 | $lang, |
||
46 | null, |
||
47 | ); |
||
48 | return true; |
||
49 | } catch (Throwable) { |
||
50 | return false; |
||
51 | } |
||
54 |