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;
27 public function __construct($autoload, $root, $appRoot)
29 $this->autoload = $autoload;
31 $this->appRoot = $appRoot;
34 public function boot($debug)
36 $output = new ConsoleOutput();
37 $input = new ArrayInput([]);
38 $io = new DrupalStyle($input, $output);
39 $argvInputReader = new ArgvInputReader();
41 if (!class_exists('Drupal\Core\DrupalKernel')) {
42 $io->error('Class Drupal\Core\DrupalKernel do not exists.');
43 $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
44 return $drupal->boot();
48 // Add support for Acquia Dev Desktop sites.
49 // Try both Mac and Windows home locations.
50 $home = getenv('HOME');
52 $home = getenv('USERPROFILE');
55 $devDesktopSettingsDir = $home . "/.acquia/DevDesktop/DrupalSettings";
56 if (file_exists($devDesktopSettingsDir)) {
57 $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devDesktopSettingsDir;
60 $argvInputReader = new ArgvInputReader();
61 $command = $argvInputReader->get('command');
62 $rebuildServicesFile = false;
63 if ($command=='cache:rebuild' || $command=='cr') {
64 $rebuildServicesFile = true;
68 $io->writeln('➤ Creating request');
70 $uri = $argvInputReader->get('uri');
71 if ($uri && $uri != 'http://default') {
72 if (substr($uri, -1) != '/') {
76 $request = Request::create($uri, 'GET', [], [], [], ['SCRIPT_NAME' => $this->appRoot . '/index.php']);
78 $request = Request::createFromGlobals();
82 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
83 $io->writeln('➤ Creating Drupal kernel');
85 $drupalKernel = DrupalKernel::createFromRequest(
93 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
94 $io->writeln('➤ Registering dynamic services');
97 $drupalKernel->addServiceModifier(
98 new DrupalServiceModifier(
107 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
108 $io->writeln('➤ Rebuilding container');
110 $drupalKernel->invalidateContainer();
111 $drupalKernel->rebuildContainer();
112 $drupalKernel->boot();
115 $io->writeln("\r\033[K\033[1A\r<info>✔</info>");
118 $container = $drupalKernel->getContainer();
119 $container->set('console.root', $this->root);
121 AnnotationRegistry::registerLoader([$this->autoload, "loadClass"]);
123 $configuration = $container->get('console.configuration_manager')
124 ->getConfiguration();
126 $container->get('console.translator_manager')
128 $configuration->get('application.language'),
132 $consoleExtendConfigFile = $this->root . DRUPAL_CONSOLE .'/extend.console.config.yml';
133 if (file_exists($consoleExtendConfigFile)) {
134 $container->get('console.configuration_manager')
135 ->importConfigurationFile($consoleExtendConfigFile);
138 $container->get('console.renderer')
141 $this->root.DRUPAL_CONSOLE.'/templates/',
142 $this->root.DRUPAL_CONSOLE_CORE.'/templates/'
147 } catch (\Exception $e) {
148 if ($argvInputReader->get('command') == 'list') {
149 $io->error($e->getMessage());
151 $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
152 $container = $drupal->boot();
153 $container->set('class_loader', $this->autoload);