-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
DrupalBoot8.php
147 lines (124 loc) · 4.07 KB
/
DrupalBoot8.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace Drush\Boot;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\DrupalKernel;
class DrupalBoot8 extends DrupalBoot {
/**
* @var \Drupal\Core\DrupalKernelInterface
*/
protected $kernel;
/**
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
function valid_root($path) {
if (!empty($path) && is_dir($path) && file_exists($path . '/index.php')) {
// Additional check for the presence of core/composer.json to
// grant it is not a Drupal 7 site with a base folder named "core".
$candidate = 'core/includes/common.inc';
if (file_exists($path . '/' . $candidate) && file_exists($path . '/core/core.services.yml')) {
if (file_exists($path . '/core/misc/drupal.js') || file_exists($path . '/core/assets/js/drupal.js')) {
return $candidate;
}
}
}
}
function get_version($drupal_root) {
// Load the autoloader so we can access the class constants.
drush_drupal_load_autoloader($drupal_root);
// Drush depends on bootstrap being loaded at this point.
require_once $drupal_root .'/core/includes/bootstrap.inc';
if (defined('Drupal::VERSION')) {
return \Drupal::VERSION;
}
}
function get_profile() {
return drupal_get_profile();
}
function conf_path($require_settings = TRUE, $reset = FALSE, Request $request = NULL) {
if (!isset($request)) {
if (\Drupal::hasRequest()) {
$request = \Drupal::request();
}
// @todo Remove once external CLI scripts (Drush) are updated.
else {
$request = Request::createFromGlobals();
}
}
if (\Drupal::hasService('kernel')) {
$site_path = \Drupal::service('kernel')->getSitePath();
}
if (!isset($site_path) || empty($site_path)) {
$site_path = DrupalKernel::findSitePath($request, $require_settings);
}
return $site_path;
}
function add_logger() {
// If we're running on Drupal 8 or later, we provide a logger which will send
// output to drush_log(). This should catch every message logged through every
// channel.
$container = \Drupal::getContainer();
$parser = $container->get('logger.log_message_parser');
$logger = new \Drush\Log\DrushLog($parser);
$container->get('logger.factory')->addLogger($logger);
}
function contrib_modules_paths() {
return array(
$this->conf_path() . '/modules',
'sites/all/modules',
'modules',
);
}
/**
* @return array of strings - paths to directories where contrib
* themes can be found
*/
function contrib_themes_paths() {
return array(
$this->conf_path() . '/themes',
'sites/all/themes',
'themes',
);
}
function bootstrap_drupal_core($drupal_root) {
$core = DRUPAL_ROOT . '/core';
return $core;
}
function bootstrap_drupal_database_validate() {
return parent::bootstrap_drupal_database_validate() && $this->bootstrap_drupal_database_has_table('key_value');
}
function bootstrap_drupal_database() {
// D8 omits this bootstrap level as nothing special needs to be done.
parent::bootstrap_drupal_database();
}
function bootstrap_drupal_configuration() {
$this->request = Request::createFromGlobals();
$classloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
$this->kernel = DrupalKernel::createFromRequest($this->request, $classloader, 'prod');
// Unset drupal error handler and restore drush's one.
restore_error_handler();
parent::bootstrap_drupal_configuration();
}
function bootstrap_drupal_full() {
if (!drush_get_context('DRUSH_QUIET', FALSE)) {
ob_start();
}
$this->kernel->boot();
$this->kernel->prepareLegacyRequest($this->request);
if (!drush_get_context('DRUSH_QUIET', FALSE)) {
ob_end_clean();
}
parent::bootstrap_drupal_full();
}
/**
* {@inheritdoc}
*/
public function terminate() {
parent::terminate();
if ($this->kernel) {
$response = Response::create('');
$this->kernel->terminate($this->request, $response);
}
}
}