Total Complexity | 7 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
11 | class TraefikUsername implements LazyExportableOption, FromEnvLazyFactory |
||
12 | { |
||
13 | const SUGGESTED_VALUE = 'admin'; |
||
14 | const TRAEFIK_UI_USERNAME = 'TRAEFIK_UI_USERNAME'; |
||
15 | const OPTION_NAME = 'traefik-ui-username'; |
||
16 | const REGEX = '/^[a-zA-Z0-9]+$/'; |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $value; |
||
21 | |||
22 | public function __construct(string $value) |
||
23 | { |
||
24 | Assertion::notEmpty($value, "The Traefik Ui username is empty"); |
||
25 | Assertion::regex( |
||
26 | $value, |
||
27 | self::REGEX, |
||
28 | "The Traefik Ui username does not contain only alphanumeric characters." |
||
29 | ); |
||
30 | $this->value = $value; |
||
31 | } |
||
32 | |||
33 | public static function fromString(string $value): self |
||
34 | { |
||
35 | return new self($value); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param Env $env |
||
40 | * @return LazyEnvironmentValue|self |
||
41 | */ |
||
42 | public static function fromEnv(Env $env): LazyEnvironmentValue |
||
43 | { |
||
44 | return new self($env->get(self::TRAEFIK_UI_USERNAME, "")); |
||
|
|||
45 | } |
||
46 | |||
47 | public static function toEnv(string $value, Env $env): void |
||
48 | { |
||
49 | $env->put(self::TRAEFIK_UI_USERNAME, $value); |
||
50 | } |
||
51 | |||
52 | public static function optionName(): string |
||
53 | { |
||
54 | return self::OPTION_NAME; |
||
55 | } |
||
56 | |||
57 | public function toString(): string |
||
58 | { |
||
59 | return $this->value; |
||
60 | } |
||
61 | |||
62 | public function __toString() |
||
65 | } |
||
66 | |||
67 | } |