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()
24 register_shutdown_function([$this, 'terminate']);
27 public function findUri($root, $uri)
32 public function setUri($uri)
37 public function validRoot($path)
41 public function getVersion($root)
45 public function commandDefaults()
49 public function reportCommandError($command)
51 // Set errors related to this command.
52 $args = implode(' ', drush_get_arguments());
53 if (isset($command) && is_array($command)) {
54 foreach ($command['bootstrap_errors'] as $key => $error) {
55 drush_set_error($key, $error);
57 drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The Drush command '!args' could not be executed.", ['!args' => $args]));
58 } elseif (!empty($args)) {
59 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]));
61 // Set errors that occurred in the bootstrap phases.
62 $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', []);
63 foreach ($errors as $code => $message) {
64 drush_set_error($code, $message);
68 public function bootstrapPhases()
71 DRUSH_BOOTSTRAP_DRUSH => 'bootstrapDrush',
75 public function bootstrapPhaseMap()
78 'none' => DRUSH_BOOTSTRAP_DRUSH,
79 'drush' => DRUSH_BOOTSTRAP_DRUSH,
80 'max' => DRUSH_BOOTSTRAP_MAX,
81 'root' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
82 'site' => DRUSH_BOOTSTRAP_DRUPAL_SITE,
83 'configuration' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION,
84 'database' => DRUSH_BOOTSTRAP_DRUPAL_DATABASE,
85 'full' => DRUSH_BOOTSTRAP_DRUPAL_FULL
89 public function lookUpPhaseIndex($phase)
91 $phaseMap = $this->bootstrapPhaseMap();
92 if (isset($phaseMap[$phase])) {
93 return $phaseMap[$phase];
96 if ((substr($phase, 0, 16) != 'DRUSH_BOOTSTRAP_') || (!defined($phase))) {
99 return constant($phase);
102 public function bootstrapDrush()
106 protected function hasRegisteredSymfonyCommand($application, $name)
109 $application->get($name);
111 } catch (\InvalidArgumentException $e) {
116 protected function inflect($object)
118 // See \Drush\Runtime\DependencyInjection::addDrushServices and
119 // \Robo\Robo\addInflectors
120 $container = $this->getContainer();
121 if ($object instanceof \Robo\Contract\ConfigAwareInterface) {
122 $object->setConfig($container->get('config'));
124 if ($object instanceof \Psr\Log\LoggerAwareInterface) {
125 $object->setLogger($container->get('logger'));
127 if ($object instanceof \League\Container\ContainerAwareInterface) {
128 $object->setContainer($container->get('container'));
130 if ($object instanceof \Symfony\Component\Console\Input\InputAwareInterface) {
131 $object->setInput($container->get('input'));
133 if ($object instanceof \Robo\Contract\OutputAwareInterface) {
134 $object->setOutput($container->get('output'));
136 if ($object instanceof \Robo\Contract\ProgressIndicatorAwareInterface) {
137 $object->setProgressIndicator($container->get('progressIndicator'));
139 if ($object instanceof \Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface) {
140 $object->setHookManager($container->get('hookManager'));
142 if ($object instanceof \Robo\Contract\VerbosityThresholdInterface) {
143 $object->setOutputAdapter($container->get('outputAdapter'));
145 if ($object instanceof \Consolidation\SiteAlias\SiteAliasManagerAwareInterface) {
146 $object->setOutputAdapter($container->get('site.alias.manager'));
153 public function terminate()