| Total Complexity | 7 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class AppSecretGeneratorCompilerPass implements CompilerPassInterface |
||
| 18 | { |
||
| 19 | public function process(ContainerBuilder $container): void |
||
| 20 | { |
||
| 21 | $projectDir = $container->getParameter('kernel.project_dir'); |
||
| 22 | $secretPath = sprintf('%s/var/app.secret', $projectDir); |
||
| 23 | $secret = null; |
||
| 24 | |||
| 25 | if (is_readable($secretPath)) { |
||
| 26 | $secret = file_get_contents($secretPath); |
||
| 27 | |||
| 28 | if (!$secret || strlen($secret) < 8) { |
||
| 29 | $secret = null; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | if (!$secret) { |
||
| 34 | $secret = $this->createSecret($secretPath); |
||
| 35 | } |
||
| 36 | |||
| 37 | $container->setParameter('env(APP_SECRET)', $secret); |
||
| 38 | } |
||
| 39 | |||
| 40 | private function createSecret(string $secretPath): string |
||
| 51 | } |
||
| 52 | } |
||
| 53 |