| Conditions | 4 |
| Paths | 5 |
| Total Lines | 46 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | public static function loadEnv(string $dir): void |
||
| 27 | { |
||
| 28 | /** @noinspection PhpIncludeInspection */ |
||
| 29 | require_once $dir . '/vendor/autoload.php'; |
||
| 30 | |||
| 31 | if (!class_exists(Dotenv::class)) { |
||
| 32 | fwrite(STDERR, 'ERROR: No se ha cargado la clase Dotenv' . PHP_EOL); |
||
| 33 | die(1); |
||
| 34 | } |
||
| 35 | |||
| 36 | try { |
||
| 37 | // Load environment variables from .env file |
||
| 38 | if (file_exists($dir . '/.env')) { |
||
| 39 | $dotenv = Dotenv::createMutable($dir, '.env'); |
||
| 40 | $dotenv->load(); |
||
| 41 | } else { |
||
| 42 | fwrite(STDERR, 'ERROR: no existe el fichero .env' . PHP_EOL); |
||
| 43 | die(1); |
||
| 44 | } |
||
| 45 | |||
| 46 | // Overload (if they exist) with .env.docker or .env.local |
||
| 47 | if (filter_has_var(INPUT_SERVER, 'DOCKER') && file_exists($dir . '/.env.docker')) { |
||
| 48 | $dotenv = Dotenv::createMutable($dir, '.env.docker'); |
||
| 49 | $dotenv->load(); |
||
| 50 | } elseif (file_exists($dir . '/.env.local')) { |
||
| 51 | $dotenv = Dotenv::createMutable($dir, '.env.local'); |
||
| 52 | $dotenv->load(); |
||
| 53 | } |
||
| 54 | } catch (Throwable $e) { |
||
| 55 | die(get_class($e) . ': ' . $e->getMessage() . PHP_EOL); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 |