artisan.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php namespace Laravel\CLI; defined('DS') or die('No direct script access.');
  2. use Laravel\Bundle;
  3. use Laravel\Config;
  4. /**
  5. * Fire up the default bundle. This will ensure any dependencies that
  6. * need to be registered in the IoC container are registered and that
  7. * the auto-loader mappings are registered.
  8. */
  9. Bundle::start(DEFAULT_BUNDLE);
  10. /**
  11. * Set the CLI options on the $_SERVER global array so we can easily
  12. * retrieve them from the various parts of the CLI code. We can use
  13. * the Request class to access them conveniently.
  14. */
  15. list($arguments, $_SERVER['CLI']) = Console::options($_SERVER['argv']);
  16. $_SERVER['CLI'] = array_change_key_case($_SERVER['CLI'], CASE_UPPER);
  17. /**
  18. * The Laravel environment may be specified on the CLI using the "env"
  19. * option, allowing the developer to easily use local configuration
  20. * files from the CLI since the environment is usually controlled
  21. * by server environmenet variables.
  22. */
  23. if (isset($_SERVER['CLI']['ENV']))
  24. {
  25. $_SERVER['LARAVEL_ENV'] = $_SERVER['CLI']['ENV'];
  26. }
  27. /**
  28. * The default database connection may be set by specifying a value
  29. * for the "database" CLI option. This allows migrations to be run
  30. * conveniently for a test or staging database.
  31. */
  32. if (isset($_SERVER['CLI']['DB']))
  33. {
  34. Config::set('database.default', $_SERVER['CLI']['DB']);
  35. }
  36. /**
  37. * We will register all of the Laravel provided tasks inside the IoC
  38. * container so they can be resolved by the task class. This allows
  39. * us to seamlessly add tasks to the CLI so that the Task class
  40. * doesn't have to worry about how to resolve core tasks.
  41. */
  42. require path('sys').'cli/dependencies'.EXT;
  43. /**
  44. * We will wrap the command execution in a try / catch block and
  45. * simply write out any exception messages we receive to the CLI
  46. * for the developer. Note that this only writes out messages
  47. * for the CLI exceptions. All others will be not be caught
  48. * and will be totally dumped out to the CLI.
  49. */
  50. try
  51. {
  52. Command::run(array_slice($arguments, 1));
  53. }
  54. catch (\Exception $e)
  55. {
  56. echo $e->getMessage();
  57. }
  58. echo PHP_EOL;