console 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env php
  2. <?php
  3. use App\Kernel;
  4. use Symfony\Bundle\FrameworkBundle\Console\Application;
  5. use Symfony\Component\Console\Input\ArgvInput;
  6. use Symfony\Component\Dotenv\Dotenv;
  7. use Symfony\Component\ErrorHandler\Debug;
  8. if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
  9. echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
  10. }
  11. set_time_limit(0);
  12. require dirname(__DIR__).'/vendor/autoload.php';
  13. if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
  14. throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
  15. }
  16. $input = new ArgvInput();
  17. if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
  18. putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
  19. }
  20. if ($input->hasParameterOption('--no-debug', true)) {
  21. putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
  22. }
  23. (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
  24. if ($_SERVER['APP_DEBUG']) {
  25. umask(0000);
  26. if (class_exists(Debug::class)) {
  27. Debug::enable();
  28. }
  29. }
  30. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  31. $application = new Application($kernel);
  32. $application->run($input);