BaseBoot.php

  1. 8.0.x lib/Drush/Boot/BaseBoot.php
  2. 7.x lib/Drush/Boot/BaseBoot.php
  3. master lib/Drush/Boot/BaseBoot.php

Namespace

Drush\Boot

Classes

Namesort descending Description
BaseBoot

File

lib/Drush/Boot/BaseBoot.php
View source
  1. <?php
  2. namespace Drush\Boot;
  3. use Drush\Log\LogLevel;
  4. abstract class BaseBoot implements Boot {
  5. function __construct() {
  6. }
  7. function valid_root($path) {
  8. }
  9. function command_defaults() {
  10. }
  11. function enforce_requirement(&$command) {
  12. drush_enforce_requirement_bootstrap_phase($command);
  13. drush_enforce_requirement_core($command);
  14. drush_enforce_requirement_drush_dependencies($command);
  15. }
  16. function report_command_error($command) {
  17. // Set errors related to this command.
  18. $args = implode(' ', drush_get_arguments());
  19. if (isset($command) && is_array($command)) {
  20. foreach ($command['bootstrap_errors'] as $key => $error) {
  21. drush_set_error($key, $error);
  22. }
  23. drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
  24. }
  25. elseif (!empty($args)) {
  26. drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The drush command '!args' could not be found. Run `drush cache-clear drush` to clear the commandfile cache if you have installed new extensions.", array('!args' => $args)));
  27. }
  28. // Set errors that occurred in the bootstrap phases.
  29. $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
  30. foreach ($errors as $code => $message) {
  31. drush_set_error($code, $message);
  32. }
  33. }
  34. function bootstrap_and_dispatch() {
  35. $phases = $this->bootstrap_init_phases();
  36. $return = '';
  37. $command_found = FALSE;
  38. _drush_bootstrap_output_prepare();
  39. foreach ($phases as $phase) {
  40. if (drush_bootstrap_to_phase($phase)) {
  41. $command = drush_parse_command();
  42. if (is_array($command)) {
  43. $command += $this->command_defaults();
  44. // Insure that we have bootstrapped to a high enough
  45. // phase for the command prior to enforcing requirements.
  46. $bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']);
  47. $this->enforce_requirement($command);
  48. if ($bootstrap_result && empty($command['bootstrap_errors'])) {
  49. drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), LogLevel::BOOTSTRAP);
  50. $command_found = TRUE;
  51. // Dispatch the command(s).
  52. $return = drush_dispatch($command);
  53. // Prevent a '1' at the end of the output.
  54. if ($return === TRUE) {
  55. $return = '';
  56. }
  57. if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) {
  58. // @todo Create version independant wrapper around Drupal timers. Use it.
  59. drush_print_timers();
  60. }
  61. break;
  62. }
  63. }
  64. }
  65. else {
  66. break;
  67. }
  68. }
  69. if (!$command_found) {
  70. // If we reach this point, command doesn't fit requirements or we have not
  71. // found either a valid or matching command.
  72. $this->report_command_error($command);
  73. }
  74. return $return;
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function terminate() {
  80. }
  81. }