c816988c45406b1e338d65dcd3fa5fbe401ef35b
[yaffs-website] / vendor / drush / drush / lib / Drush / Boot / BaseBoot.php
1 <?php
2
3 namespace Drush\Boot;
4
5 use Drush\Log\LogLevel;
6
7 abstract class BaseBoot implements Boot {
8
9   function __construct() {
10   }
11
12   function valid_root($path) {
13   }
14
15   function get_version($root) {
16   }
17
18   function command_defaults() {
19   }
20
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);
25   }
26
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);
33       }
34       drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
35     }
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)));
38     }
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);
43     }
44   }
45
46   function bootstrap_and_dispatch() {
47     $phases = $this->bootstrap_init_phases();
48
49     $return = '';
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);
61
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);
64
65             $command_found = TRUE;
66             // Dispatch the command(s).
67             $return = drush_dispatch($command);
68
69             // Prevent a '1' at the end of the output.
70             if ($return === TRUE) {
71               $return = '';
72             }
73
74             if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) {
75               // @todo Create version independant wrapper around Drupal timers. Use it.
76               drush_print_timers();
77             }
78             break;
79           }
80         }
81       }
82       else {
83         break;
84       }
85     }
86
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);
91     }
92     return $return;
93   }
94
95   /**
96    * {@inheritdoc}
97    */
98   public function terminate() {
99   }
100 }