1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Nexendrie\Translation\Resolvers; |
||
5 | |||
6 | use Nexendrie\Translation\ISettableLocaleResolver; |
||
7 | |||
8 | /** |
||
9 | * EnvironmentResolver |
||
10 | * Reads current language from an environment variable |
||
11 | * |
||
12 | * @author Jakub Konečný |
||
13 | * @property string|null $lang |
||
14 | */ |
||
15 | 1 | final class EnvironmentLocaleResolver implements ISettableLocaleResolver { |
|
16 | use \Nette\SmartObject; |
||
17 | |||
18 | public string $varName = "TRANSLATOR_LANGUAGE"; |
||
19 | |||
20 | /** |
||
21 | * @deprecated Access the property directly |
||
22 | */ |
||
23 | public function getLang(): ?string { |
||
24 | 1 | $lang = getenv($this->varName); |
|
25 | 1 | if(is_string($lang)) { |
|
26 | 1 | return $lang; |
|
27 | } |
||
28 | 1 | return null; |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * @deprecated Access the property directly |
||
33 | */ |
||
34 | public function setLang(?string $lang): void { |
||
35 | 1 | if($lang === null) { |
|
36 | 1 | putenv($this->varName); |
|
37 | } else { |
||
38 | 1 | putenv($this->varName . "=$lang"); |
|
39 | } |
||
40 | 1 | } |
|
41 | |||
42 | /** |
||
43 | * @deprecated Access the property directly |
||
44 | */ |
||
45 | public function getVarName(): string { |
||
46 | return $this->varName; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @deprecated Access the property directly |
||
51 | */ |
||
52 | public function setVarName(string $varName): void { |
||
53 | $this->varName = $varName; |
||
54 | } |
||
55 | |||
56 | public function resolve(): ?string { |
||
57 | 1 | return $this->getLang(); |
|
0 ignored issues
–
show
|
|||
58 | } |
||
59 | } |
||
60 | ?> |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.