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