6 use Drush\Log\LogLevel;
7 use Psr\Log\LoggerInterface;
8 use Psr\Log\LoggerAwareInterface;
9 use Psr\Log\LoggerAwareTrait;
10 use League\Container\ContainerAwareInterface;
11 use League\Container\ContainerAwareTrait;
13 use Symfony\Component\Console\Input\ArgvInput;
15 abstract class BaseBoot implements Boot, LoggerAwareInterface, ContainerAwareInterface
18 use ContainerAwareTrait;
22 public function __construct()
26 public function findUri($root, $uri)
31 public function setUri($uri)
36 public function validRoot($path)
40 public function getVersion($root)
44 public function commandDefaults()
48 public function reportCommandError($command)
50 // Set errors related to this command.
51 $args = implode(' ', drush_get_arguments());
52 if (isset($command) && is_array($command)) {
53 foreach ($command['bootstrap_errors'] as $key => $error) {
54 drush_set_error($key, $error);
56 drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The Drush command '!args' could not be executed.", ['!args' => $args]));
57 } elseif (!empty($args)) {
58 drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The Drush command '!args' could not be found. Use 'drush core-status' to verify that Drupal is found and bootstrapped successfully. Look for 'Drupal bootstrap : Successful' in its output.", ['!args' => $args]));
60 // Set errors that occurred in the bootstrap phases.
61 $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', []);
62 foreach ($errors as $code => $message) {
63 drush_set_error($code, $message);
67 public function bootstrapPhases()
70 DRUSH_BOOTSTRAP_DRUSH => 'bootstrapDrush',
74 public function bootstrapPhaseMap()
77 'none' => DRUSH_BOOTSTRAP_DRUSH,
78 'drush' => DRUSH_BOOTSTRAP_DRUSH,
79 'max' => DRUSH_BOOTSTRAP_MAX,
80 'root' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
81 'site' => DRUSH_BOOTSTRAP_DRUPAL_SITE,
82 'configuration' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION,
83 'database' => DRUSH_BOOTSTRAP_DRUPAL_DATABASE,
84 'full' => DRUSH_BOOTSTRAP_DRUPAL_FULL
88 public function lookUpPhaseIndex($phase)
90 $phaseMap = $this->bootstrapPhaseMap();
91 if (isset($phaseMap[$phase])) {
92 return $phaseMap[$phase];
95 if ((substr($phase, 0, 16) != 'DRUSH_BOOTSTRAP_') || (!defined($phase))) {
98 return constant($phase);
101 public function bootstrapDrush()
105 protected function hasRegisteredSymfonyCommand($application, $name)
108 $application->get($name);
110 } catch (\InvalidArgumentException $e) {
115 protected function inflect($object)
117 // See \Drush\Runtime\DependencyInjection::addDrushServices and
118 // \Robo\Robo\addInflectors
119 $container = $this->getContainer();
120 if ($object instanceof \Robo\Contract\ConfigAwareInterface) {
121 $object->setConfig($container->get('config'));
123 if ($object instanceof \Psr\Log\LoggerAwareInterface) {
124 $object->setLogger($container->get('logger'));
126 if ($object instanceof \League\Container\ContainerAwareInterface) {
127 $object->setContainer($container->get('container'));
129 if ($object instanceof \Symfony\Component\Console\Input\InputAwareInterface) {
130 $object->setInput($container->get('input'));
132 if ($object instanceof \Robo\Contract\OutputAwareInterface) {
133 $object->setOutput($container->get('output'));
135 if ($object instanceof \Robo\Contract\ProgressIndicatorAwareInterface) {
136 $object->setProgressIndicator($container->get('progressIndicator'));
138 if ($object instanceof \Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface) {
139 $object->setHookManager($container->get('hookManager'));
141 if ($object instanceof \Robo\Contract\VerbosityThresholdInterface) {
142 $object->setOutputAdapter($container->get('outputAdapter'));
144 if ($object instanceof \Drush\SiteAlias\SiteAliasManagerAwareInterface) {
145 $object->setOutputAdapter($container->get('site.alias.manager'));
152 public function terminate()