artisan.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php namespace Laravel\CLI; defined('DS') or die('No direct script access.');
  2. use Laravel\Bundle;
  3. use Laravel\Config;
  4. use Laravel\Request;
  5. /**
  6. * Fire up the default bundle. This will ensure any dependencies that
  7. * need to be registered in the IoC container are registered and that
  8. * the auto-loader mappings are registered.
  9. */
  10. Bundle::start(DEFAULT_BUNDLE);
  11. /**
  12. * The default database connection may be set by specifying a value
  13. * for the "database" CLI option. This allows migrations to be run
  14. * conveniently for a test or staging database.
  15. */
  16. if (isset($_SERVER['CLI']['DB']))
  17. {
  18. Config::set('database.default', $_SERVER['CLI']['DB']);
  19. }
  20. /**
  21. * Overwrite the HttpFoundation request since we have set some of
  22. * the server variables since it was created. This allows us to
  23. * set the default database for the CLI task.
  24. */
  25. use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
  26. Request::$foundation = RequestFoundation::createFromGlobals();
  27. /**
  28. * We will register all of the Laravel provided tasks inside the IoC
  29. * container so they can be resolved by the task class. This allows
  30. * us to seamlessly add tasks to the CLI so that the Task class
  31. * doesn't have to worry about how to resolve core tasks.
  32. */
  33. require path('sys').'cli/dependencies'.EXT;
  34. /**
  35. * We will wrap the command execution in a try / catch block and
  36. * simply write out any exception messages we receive to the CLI
  37. * for the developer. Note that this only writes out messages
  38. * for the CLI exceptions. All others will be not be caught
  39. * and will be totally dumped out to the CLI.
  40. */
  41. try
  42. {
  43. Command::run(array_slice($arguments, 1));
  44. }
  45. catch (\Exception $e)
  46. {
  47. echo $e->getMessage();
  48. }
  49. echo PHP_EOL;