| Total Complexity | 7 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 11 | class StaticSiteNamespace implements LazyExportableOption, FromEnvLazyFactory |
||
| 12 | { |
||
| 13 | const STATIC_SITE_NAMESPACE = 'STATIC_SITE_NAMESPACE'; |
||
| 14 | const OPTION_NAME = 'namespace'; |
||
| 15 | const REGEX = '/^[a-z0-9-]+$/'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $value; |
||
| 21 | |||
| 22 | public function __construct(string $value) |
||
| 23 | { |
||
| 24 | Assertion::notEmpty($value, "The site namespace is empty"); |
||
| 25 | Assertion::regex( |
||
| 26 | $value, |
||
| 27 | self::REGEX, |
||
| 28 | "The site namespace does not contain only lowercase letters, digits and -" |
||
| 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::STATIC_SITE_NAMESPACE, "")); |
||
|
|
|||
| 45 | } |
||
| 46 | |||
| 47 | public static function toEnv(string $value, Env $env): void |
||
| 48 | { |
||
| 49 | $env->put(self::STATIC_SITE_NAMESPACE, $value); |
||
| 50 | } |
||
| 51 | |||
| 52 | public static function optionName(): string |
||
| 53 | { |
||
| 54 | return self::OPTION_NAME; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function toString(): string |
||
| 60 | } |
||
| 61 | |||
| 62 | public function __toString() |
||
| 65 | } |
||
| 66 | |||
| 67 | } |