-
-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathDrupal.php
More file actions
240 lines (209 loc) · 8.27 KB
/
Drupal.php
File metadata and controls
240 lines (209 loc) · 8.27 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
namespace Drupal\Console\Bootstrap;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Core\Utils\ArgvInputReader;
use Drupal\Console\Core\Bootstrap\DrupalConsoleCore;
use Drupal\Console\Core\Utils\DrupalFinder;
use Drupal\Console\Extension\Extension;
use Drupal\Console\Extension\Manager;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
class Drupal
{
protected $autoload;
/**
* @var DrupalFinder
*/
protected $drupalFinder;
/**
* Drupal constructor.
*
* @param $autoload
* @param $drupalFinder
*/
public function __construct($autoload, DrupalFinder $drupalFinder)
{
$this->autoload = $autoload;
$this->drupalFinder = $drupalFinder;
}
public function boot()
{
$output = new ConsoleOutput();
$input = new ArrayInput([]);
$io = new DrupalStyle($input, $output);
$argvInputReader = new ArgvInputReader();
$command = $argvInputReader->get('command');
$uri = $argvInputReader->get('uri');
$debug = $argvInputReader->get('debug', false);
if ($debug) {
$binaryPath = $this->drupalFinder->getVendorDir() .
'/drupal/console/bin/drupal';
$io->writeln("<info>Per-Site path:</info> <comment>$binaryPath</comment>");
$io->newLine();
}
if (!class_exists('Drupal\Core\DrupalKernel')) {
$io->error('Class Drupal\Core\DrupalKernel does not exist.');
$drupal = new DrupalConsoleCore(
$this->drupalFinder->getComposerRoot(),
$this->drupalFinder->getDrupalRoot()
);
return $drupal->boot();
}
try {
// Add support for Acquia Dev Desktop sites.
// Try both Mac and Windows home locations.
$home = getenv('HOME');
if (empty($home)) {
$home = getenv('USERPROFILE');
}
if (!empty($home)) {
$devDesktopSettingsDir = $home . "/.acquia/DevDesktop/DrupalSettings";
if (file_exists($devDesktopSettingsDir)) {
$_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devDesktopSettingsDir;
}
}
$rebuildServicesFile = false;
if ($command=='cache:rebuild' || $command=='cr') {
$rebuildServicesFile = true;
}
if ($debug) {
$io->writeln('➤ Creating request');
}
$_SERVER['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
$_SERVER['SERVER_PORT'] = null;
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_SOFTWARE'] = null;
$_SERVER['HTTP_USER_AGENT'] = null;
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] . 'index.php';
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['SCRIPT_FILENAME'] = $this->drupalFinder->getDrupalRoot() . '/index.php';
$request = Request::createFromGlobals();
if ($debug) {
$io->writeln("\r\033[K\033[1A\r<info>✔</info>");
$io->writeln('➤ Creating Drupal kernel');
}
$drupalKernel = DrupalKernel::createFromRequest(
$request,
$this->autoload,
'prod',
false,
$this->drupalFinder->getDrupalRoot()
);
if ($debug) {
$io->writeln("\r\033[K\033[1A\r<info>✔</info>");
$io->writeln('➤ Registering dynamic services');
}
$drupalKernel->addServiceModifier(
new DrupalServiceModifier(
$this->drupalFinder->getComposerRoot(),
$this->drupalFinder->getDrupalRoot(),
'drupal.command',
'drupal.generator',
$rebuildServicesFile
)
);
if ($debug) {
$io->writeln("\r\033[K\033[1A\r<info>✔</info>");
$io->writeln('➤ Rebuilding container');
}
$drupalKernel->invalidateContainer();
$drupalKernel->rebuildContainer();
$drupalKernel->boot();
if ($debug) {
$io->writeln("\r\033[K\033[1A\r<info>✔</info>");
}
$container = $drupalKernel->getContainer();
$container->set(
'console.root',
$this->drupalFinder->getComposerRoot()
);
AnnotationRegistry::registerLoader([$this->autoload, "loadClass"]);
$configuration = $container->get('console.configuration_manager')
->getConfiguration();
$container->get('console.translator_manager')
->loadCoreLanguage(
$configuration->get('application.language'),
$this->drupalFinder->getComposerRoot()
);
$consoleExtendConfigFile = $this->drupalFinder->getComposerRoot() . DRUPAL_CONSOLE .'/extend.console.config.yml';
if (file_exists($consoleExtendConfigFile)) {
$container->get('console.configuration_manager')
->importConfigurationFile($consoleExtendConfigFile);
}
$container->get('console.renderer')
->setSkeletonDirs(
[
$this->drupalFinder->getComposerRoot().DRUPAL_CONSOLE.'/templates/',
$this->drupalFinder->getComposerRoot().DRUPAL_CONSOLE_CORE.'/templates/'
]
);
return $container;
} catch (\Exception $e) {
if ($command == 'list') {
$io->error($e->getMessage());
}
$drupal = new DrupalConsoleCore(
$this->drupalFinder->getComposerRoot(),
$this->drupalFinder->getDrupalRoot()
);
$container = $drupal->boot();
$container->set('class_loader', $this->autoload);
// Workaround to load commands from profiles.
// Drupal and the profile are not yet installed at this point.
$loader = new YamlFileLoader(
$container,
new FileLocator($this->drupalFinder->getDrupalRoot())
);
/**
* @var Manager $extensionManager
*/
$extensionManager = $container->get('console.extension_manager');
$profiles = $extensionManager->discoverProfiles()
->showNoCore()
->showUninstalled()
->getList(false);
/**
* @var Extension[] $profiles
*/
foreach ($profiles as $profile) {
$profilePath = sprintf(
'%s/%s',
$this->drupalFinder->getDrupalRoot(),
$profile->getPath()
);
$profileDirectories = [
sprintf(
'%s/src/Command',
$profilePath
),
sprintf(
'%s/src/Generator',
$profilePath
)
];
// Load Command & Generator Classes
$finder = new Finder();
$finder->files()
->name('*.php')
->in($profileDirectories);
foreach ($finder as $file) {
echo $file->getRealPath() . PHP_EOL;
require_once($file->getRealPath());
}
$consoleServicesExtensionFile = $profilePath .
'/console.services.yml';
if (is_file($consoleServicesExtensionFile)) {
$loader->load($consoleServicesExtensionFile);
}
}
return $container;
}
}
}