5 use Drush\Log\LogLevel;
7 abstract class BaseBoot implements Boot {
9 function __construct() {
12 function valid_root($path) {
15 function get_version($root) {
18 function command_defaults() {
21 function enforce_requirement(&$command) {
22 drush_enforce_requirement_bootstrap_phase($command);
23 drush_enforce_requirement_core($command);
24 drush_enforce_requirement_drush_dependencies($command);
27 function report_command_error($command) {
28 // Set errors related to this command.
29 $args = implode(' ', drush_get_arguments());
30 if (isset($command) && is_array($command)) {
31 foreach ($command['bootstrap_errors'] as $key => $error) {
32 drush_set_error($key, $error);
34 drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
36 elseif (!empty($args)) {
37 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)));
39 // Set errors that occurred in the bootstrap phases.
40 $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
41 foreach ($errors as $code => $message) {
42 drush_set_error($code, $message);
46 function bootstrap_and_dispatch() {
47 $phases = $this->bootstrap_init_phases();
50 $command_found = FALSE;
51 _drush_bootstrap_output_prepare();
52 foreach ($phases as $phase) {
53 if (drush_bootstrap_to_phase($phase)) {
54 $command = drush_parse_command();
55 if (is_array($command)) {
56 $command += $this->command_defaults();
57 // Insure that we have bootstrapped to a high enough
58 // phase for the command prior to enforcing requirements.
59 $bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']);
60 $this->enforce_requirement($command);
62 if ($bootstrap_result && empty($command['bootstrap_errors'])) {
63 drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), LogLevel::BOOTSTRAP);
65 $command_found = TRUE;
66 // Dispatch the command(s).
67 $return = drush_dispatch($command);
69 // Prevent a '1' at the end of the output.
70 if ($return === TRUE) {
74 if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) {
75 // @todo Create version independant wrapper around Drupal timers. Use it.
87 if (!$command_found) {
88 // If we reach this point, command doesn't fit requirements or we have not
89 // found either a valid or matching command.
90 $this->report_command_error($command);
98 public function terminate() {