c9bfed9d2655f407ec0fa78ca9441c3857788751
[yaffs-website] / vendor / drush / drush / src / Boot / BaseBoot.php
1 <?php
2
3 namespace Drush\Boot;
4
5 use Drush\Drush;
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;
12
13 use Symfony\Component\Console\Input\ArgvInput;
14
15 abstract class BaseBoot implements Boot, LoggerAwareInterface, ContainerAwareInterface
16 {
17     use LoggerAwareTrait;
18     use ContainerAwareTrait;
19
20     protected $uri;
21
22     public function __construct()
23     {
24     }
25
26     public function findUri($root, $uri)
27     {
28         return 'default';
29     }
30
31     public function setUri($uri)
32     {
33         $this->uri = $uri;
34     }
35
36     public function validRoot($path)
37     {
38     }
39
40     public function getVersion($root)
41     {
42     }
43
44     public function commandDefaults()
45     {
46     }
47
48     public function reportCommandError($command)
49     {
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);
55             }
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]));
59         }
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);
64         }
65     }
66
67     public function bootstrapPhases()
68     {
69         return [
70             DRUSH_BOOTSTRAP_DRUSH => 'bootstrapDrush',
71         ];
72     }
73
74     public function bootstrapPhaseMap()
75     {
76         return [
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
85         ];
86     }
87
88     public function lookUpPhaseIndex($phase)
89     {
90         $phaseMap = $this->bootstrapPhaseMap();
91         if (isset($phaseMap[$phase])) {
92             return $phaseMap[$phase];
93         }
94
95         if ((substr($phase, 0, 16) != 'DRUSH_BOOTSTRAP_') || (!defined($phase))) {
96             return;
97         }
98         return constant($phase);
99     }
100
101     public function bootstrapDrush()
102     {
103     }
104
105     protected function hasRegisteredSymfonyCommand($application, $name)
106     {
107         try {
108             $application->get($name);
109             return true;
110         } catch (\InvalidArgumentException $e) {
111             return false;
112         }
113     }
114
115     protected function inflect($object)
116     {
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'));
122         }
123         if ($object instanceof \Psr\Log\LoggerAwareInterface) {
124             $object->setLogger($container->get('logger'));
125         }
126         if ($object instanceof \League\Container\ContainerAwareInterface) {
127             $object->setContainer($container->get('container'));
128         }
129         if ($object instanceof \Symfony\Component\Console\Input\InputAwareInterface) {
130             $object->setInput($container->get('input'));
131         }
132         if ($object instanceof \Robo\Contract\OutputAwareInterface) {
133             $object->setOutput($container->get('output'));
134         }
135         if ($object instanceof \Robo\Contract\ProgressIndicatorAwareInterface) {
136             $object->setProgressIndicator($container->get('progressIndicator'));
137         }
138         if ($object instanceof \Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface) {
139             $object->setHookManager($container->get('hookManager'));
140         }
141         if ($object instanceof \Robo\Contract\VerbosityThresholdInterface) {
142             $object->setOutputAdapter($container->get('outputAdapter'));
143         }
144         if ($object instanceof \Drush\SiteAlias\SiteAliasManagerAwareInterface) {
145             $object->setOutputAdapter($container->get('site.alias.manager'));
146         }
147     }
148
149     /**
150      * {@inheritdoc}
151      */
152     public function terminate()
153     {
154     }
155 }