3 namespace Drupal\Console\Bootstrap;
5 use Doctrine\Common\Annotations\AnnotationRegistry;
6 use Symfony\Component\Console\Input\ArrayInput;
7 use Symfony\Component\Console\Output\ConsoleOutput;
8 use Symfony\Component\HttpFoundation\Request;
9 use Drupal\Console\Core\Style\DrupalStyle;
10 use Drupal\Console\Core\Utils\ArgvInputReader;
11 use Drupal\Console\Core\Bootstrap\DrupalConsoleCore;
12 use Drupal\Console\Utils\ExtendExtensionManager;
13 use Drupal\Console\Core\Utils\DrupalFinder;
22 protected $drupalFinder;
28 * @param $drupalFinder
30 public function __construct($autoload, DrupalFinder $drupalFinder)
32 $this->autoload = $autoload;
33 $this->drupalFinder = $drupalFinder;
36 public function boot()
38 $output = new ConsoleOutput();
39 $input = new ArrayInput([]);
40 $io = new DrupalStyle($input, $output);
41 $argvInputReader = new ArgvInputReader();
42 $command = $argvInputReader->get('command');
43 $uri = $argvInputReader->get('uri');
44 $debug = $argvInputReader->get('debug', false);
47 $binaryPath = $this->drupalFinder->getVendorDir() .
48 '/drupal/console/bin/drupal';
49 $io->writeln("<info>Per-Site path:</info> <comment>$binaryPath</comment>");
53 if (!class_exists('Drupal\Core\DrupalKernel')) {
54 $io->error('Class Drupal\Core\DrupalKernel does not exist.');
55 $drupal = new DrupalConsoleCore(
56 $this->drupalFinder->getComposerRoot(),
57 $this->drupalFinder->getDrupalRoot()
59 return $drupal->boot();
63 // Add support for Acquia Dev Desktop sites.
64 // Try both Mac and Windows home locations.
65 $home = getenv('HOME');
67 $home = getenv('USERPROFILE');
70 $devDesktopSettingsDir = $home . "/.acquia/DevDesktop/DrupalSettings";
71 if (file_exists($devDesktopSettingsDir)) {
72 $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devDesktopSettingsDir;
76 $rebuildServicesFile = false;
77 if ($command=='cache:rebuild' || $command=='cr') {
78 $rebuildServicesFile = true;
82 $io->writeln('➤ Creating request');
85 $_SERVER['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
86 $_SERVER['SERVER_PORT'] = null;
87 $_SERVER['REQUEST_URI'] = '/';
88 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
89 $_SERVER['REQUEST_METHOD'] = 'GET';
90 $_SERVER['SERVER_SOFTWARE'] = null;
91 $_SERVER['HTTP_USER_AGENT'] = null;
92 $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] . 'index.php';
93 $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
94 $_SERVER['SCRIPT_FILENAME'] = $this->drupalFinder->getDrupalRoot() . '/index.php';
95 $request = Request::createFromGlobals();
98 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
99 $io->writeln('➤ Creating Drupal kernel');
102 $drupalKernel = DrupalKernel::createFromRequest(
107 $this->drupalFinder->getDrupalRoot()
110 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
111 $io->writeln('➤ Registering dynamic services');
114 $drupalKernel->addServiceModifier(
115 new DrupalServiceModifier(
116 $this->drupalFinder->getComposerRoot(),
117 $this->drupalFinder->getDrupalRoot(),
125 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
126 $io->writeln('➤ Rebuilding container');
128 $drupalKernel->invalidateContainer();
129 $drupalKernel->rebuildContainer();
130 $drupalKernel->boot();
133 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
136 $container = $drupalKernel->getContainer();
139 $this->drupalFinder->getComposerRoot()
142 AnnotationRegistry::registerLoader([$this->autoload, "loadClass"]);
144 $configuration = $container->get('console.configuration_manager')
145 ->getConfiguration();
147 $container->get('console.translator_manager')
149 $configuration->get('application.language'),
150 $this->drupalFinder->getComposerRoot()
153 $consoleExtendConfigFile = $this->drupalFinder->getComposerRoot() . DRUPAL_CONSOLE .'/extend.console.config.yml';
154 if (file_exists($consoleExtendConfigFile)) {
155 $container->get('console.configuration_manager')
156 ->importConfigurationFile($consoleExtendConfigFile);
159 $container->get('console.renderer')
162 $this->drupalFinder->getComposerRoot().DRUPAL_CONSOLE.'/templates/',
163 $this->drupalFinder->getComposerRoot().DRUPAL_CONSOLE_CORE.'/templates/'
168 } catch (\Exception $e) {
169 if ($command == 'list') {
170 $io->error($e->getMessage());
172 $drupal = new DrupalConsoleCore(
173 $this->drupalFinder->getComposerRoot(),
174 $this->drupalFinder->getDrupalRoot()
176 $container = $drupal->boot();
177 $container->set('class_loader', $this->autoload);