|
3 | 3 |
|
4 | 4 | use App\Kernel;
|
5 | 5 | use Symfony\Bundle\FrameworkBundle\Console\Application;
|
| 6 | +use Symfony\Component\Console\Input\ArgvInput; |
6 | 7 | use Symfony\Component\Debug\Debug;
|
7 |
| -use Symfony\Component\Dotenv\Dotenv; |
8 | 8 |
|
9 | 9 | set_time_limit(0);
|
10 | 10 |
|
11 |
| -require __DIR__.'/../vendor/autoload.php'; |
| 11 | +require dirname(__DIR__).'/vendor/autoload.php'; |
12 | 12 |
|
13 | 13 | if (!class_exists(Application::class)) {
|
14 |
| - throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.'); |
| 14 | + throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.'); |
15 | 15 | }
|
16 | 16 |
|
17 |
| -if (!isset($_SERVER['APP_ENV'])) { |
18 |
| - if (!class_exists(Dotenv::class)) { |
19 |
| - throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'); |
20 |
| - } |
21 |
| - (new Dotenv())->load(__DIR__.'/../.env'); |
| 17 | +$input = new ArgvInput(); |
| 18 | +if (null !== $_ENV['APP_ENV'] = $input->getParameterOption(['--env', '-e'], null, true)) { |
| 19 | + putenv('APP_ENV='.$_ENV['APP_ENV']); |
| 20 | + // force loading .env files when --env is defined |
| 21 | + $_SERVER['APP_ENV'] = null; |
| 22 | +} |
| 23 | + |
| 24 | +if ($input->hasParameterOption('--no-debug', true)) { |
| 25 | + putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); |
22 | 26 | }
|
23 | 27 |
|
24 |
| -$env = $_SERVER['APP_ENV'] ?? 'dev'; |
25 |
| -$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)); |
| 28 | +require dirname(__DIR__).'/config/bootstrap.php'; |
26 | 29 |
|
27 |
| -if ($debug) { |
| 30 | +if ($_SERVER['APP_DEBUG']) { |
28 | 31 | umask(0000);
|
29 | 32 |
|
30 | 33 | if (class_exists(Debug::class)) {
|
31 | 34 | Debug::enable();
|
32 | 35 | }
|
33 | 36 | }
|
34 | 37 |
|
35 |
| -$kernel = new Kernel($env, $debug); |
| 38 | +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); |
36 | 39 | $application = new Application($kernel);
|
37 |
| -$application->run(); |
| 40 | +$application->run($input); |
0 commit comments