abstract class BaseBoot

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

Namespace

Drush\Boot

Hierarchy

Expanded class hierarchy of BaseBoot

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
BaseBoot::bootstrap_and_dispatch function Main entrypoint to bootstrap the selected CMS and execute the selected command. Overrides Boot::bootstrap_and_dispatch
BaseBoot::command_defaults function Return an array of default values that should be added to every command (e.g. values needed in enforce_requirements(), etc.) Overrides Boot::command_defaults
BaseBoot::enforce_requirement function Called by Drush when a command is selected, but before it runs. This gives the Boot class an opportunity to determine if any minimum requirements (e.g. minimum Drupal version) declared in the command have been met. Overrides Boot::enforce_requirement
BaseBoot::get_version function Given a site root directory, determine the exact version of the software. Overrides Boot::get_version
BaseBoot::report_command_error function Called by Drush if a command is not found, or if the command was found, but did not meet requirements. Overrides Boot::report_command_error
BaseBoot::terminate public function This method is called during the shutdown of drush. Overrides Boot::terminate
BaseBoot::valid_root function This function determines if the specified path points to the root directory of a CMS that can be bootstrapped by the specific subclass that implements it. Overrides Boot::valid_root
BaseBoot::__construct function
Boot::bootstrap_init_phases function List of bootstrap phases where Drush should stop and look for commandfiles.
Boot::bootstrap_phases function Returns an array that determines what bootstrap phases are necessary to bootstrap this CMS. This array should map from a numeric phase to the name of a method (string) in the Boot class that handles the bootstrap phase.

File

lib/Drush/Boot/BaseBoot.php, line 7

View source
abstract class BaseBoot implements Boot {

  function __construct() {
  }

  function valid_root($path) {
  }

  function get_version($root) {
  }

  function command_defaults() {
  }

  function enforce_requirement(&$command) {
    drush_enforce_requirement_bootstrap_phase($command);
    drush_enforce_requirement_core($command);
    drush_enforce_requirement_drush_dependencies($command);
  }

  function report_command_error($command) {
    // Set errors related to this command.
    $args = implode(' ', drush_get_arguments());
    if (isset($command) && is_array($command)) {
      foreach ($command['bootstrap_errors'] as $key => $error) {
        drush_set_error($key, $error);
      }
      drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
    }
    elseif (!empty($args)) {
      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)));
    }
    // Set errors that occurred in the bootstrap phases.
    $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
    foreach ($errors as $code => $message) {
      drush_set_error($code, $message);
    }
  }

  function bootstrap_and_dispatch() {
    $phases = $this->bootstrap_init_phases();

    $return = '';
    $command_found = FALSE;
    _drush_bootstrap_output_prepare();
    foreach ($phases as $phase) {
      if (drush_bootstrap_to_phase($phase)) {
        $command = drush_parse_command();
        if (is_array($command)) {
          $command += $this->command_defaults();
          // Insure that we have bootstrapped to a high enough
          // phase for the command prior to enforcing requirements.
          $bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']);
          $this->enforce_requirement($command);

          if ($bootstrap_result && empty($command['bootstrap_errors'])) {
            drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), LogLevel::BOOTSTRAP);

            $command_found = TRUE;
            // Dispatch the command(s).
            $return = drush_dispatch($command);

            // Prevent a '1' at the end of the output.
            if ($return === TRUE) {
              $return = '';
            }

            if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) {
              // @todo Create version independant wrapper around Drupal timers. Use it.
              drush_print_timers();
            }
            break;
          }
        }
      }
      else {
        break;
      }
    }

    if (!$command_found) {
      // If we reach this point, command doesn't fit requirements or we have not
      // found either a valid or matching command.
      $this->report_command_error($command);
    }
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  public function terminate() {
  }
}