artisan.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php namespace Laravel\CLI; isset($GLOBALS['APP_PATH']) 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. /**
  17. * The Laravel environment may be specified on the CLI using the "env"
  18. * option, allowing the developer to easily use local configuration
  19. * files from the CLI since the environment is usually controlled
  20. * by server environmenet variables.
  21. */
  22. if (isset($_SERVER['cli']['env']))
  23. {
  24. $_SERVER['LARAVEL_ENV'] = $_SERVER['cli']['env'];
  25. }
  26. /**
  27. * The default database connection may be set by specifying a value
  28. * for the "database" CLI option. This allows migrations to be run
  29. * conveniently for a test or staging database.
  30. */
  31. if (isset($_SERVER['cli']['db']))
  32. {
  33. Config::set('database.default', $_SERVER['cli']['db']);
  34. }
  35. /**
  36. * We will register all of the Laravel provided tasks inside the IoC
  37. * container so they can be resolved by the task class. This allows
  38. * us to seamlessly add tasks to the CLI so that the Task class
  39. * doesn't have to worry about how to resolve core tasks.
  40. */
  41. require $GLOBALS['SYS_PATH'].'cli/dependencies'.EXT;
  42. /**
  43. * We will wrap the command execution in a try / catch block and
  44. * simply write out any exception messages we receive to the CLI
  45. * for the developer. Note that this only writes out messages
  46. * for the CLI exceptions. All others will be not be caught
  47. * and will be totally dumped out to the CLI.
  48. */
  49. try
  50. {
  51. Command::run(array_slice($arguments, 1));
  52. }
  53. catch (\Exception $e)
  54. {
  55. echo $e->getMessage();
  56. }
  57. echo PHP_EOL;