console 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // Prevent doctrine:schema:update to be executed during the progressive migration
  31. if (in_array($input->getFirstArgument(), ["d:s:u", "doctrine:schema:update"])) {
  32. throw new \InvalidArgumentException("<!> schema:update should not be used here for the time of the progressive migration");
  33. }
  34. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  35. $application = new Application($kernel);
  36. $application->run($input);