| Total Complexity | 10 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 18 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class LoadYamlEnvironmentVariables |
||
| 16 | { |
||
| 17 | protected YamlConfigurationRepository $yaml; |
||
| 18 | |||
| 19 | public function bootstrap(Application $app): void |
||
| 20 | { |
||
| 21 | $this->yaml = $app->make(YamlConfigurationRepository::class); |
||
| 22 | |||
| 23 | if ($this->yaml->hasYamlConfigFile()) { |
||
| 24 | $this->injectEnvironmentVariables(); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | protected function injectEnvironmentVariables(): void |
||
| 29 | { |
||
| 30 | if ($this->canInjectSiteNameEnvironmentVariable()) { |
||
| 31 | $this->injectSiteNameEnvironmentVariable(); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | protected function canInjectSiteNameEnvironmentVariable(): bool |
||
| 36 | { |
||
| 37 | return $this->yamlHasSiteNameSet() && ! $this->alreadyHasEnvironmentVariable(); |
||
| 38 | } |
||
| 39 | |||
| 40 | protected function alreadyHasEnvironmentVariable(): bool |
||
| 43 | } |
||
| 44 | |||
| 45 | protected function injectSiteNameEnvironmentVariable(): void |
||
| 46 | { |
||
| 47 | $name = $this->getSiteNameFromYaml(); |
||
| 48 | |||
| 49 | Env::getRepository()->set('SITE_NAME', $name); |
||
| 50 | } |
||
| 51 | |||
| 52 | protected function yamlHasSiteNameSet(): bool |
||
| 53 | { |
||
| 54 | return isset($this->yaml->getData()['hyde']['name']); |
||
| 55 | } |
||
| 56 | |||
| 57 | protected function getSiteNameFromYaml(): string |
||
| 60 | } |
||
| 61 | } |
||
| 62 |