use Drupal\Console\Core\Utils\ArgvInputReader;
use Drupal\Console\Core\Bootstrap\DrupalConsoleCore;
use Drupal\Console\Utils\ExtendExtensionManager;
+use Drupal\Console\Core\Utils\DrupalFinder;
class Drupal
{
protected $autoload;
- protected $root;
- protected $appRoot;
+
+ /**
+ * @var DrupalFinder
+ */
+ protected $drupalFinder;
/**
* Drupal constructor.
*
* @param $autoload
- * @param $root
- * @param $appRoot
+ * @param $drupalFinder
*/
- public function __construct($autoload, $root, $appRoot)
+ public function __construct($autoload, DrupalFinder $drupalFinder)
{
$this->autoload = $autoload;
- $this->root = $root;
- $this->appRoot = $appRoot;
+ $this->drupalFinder = $drupalFinder;
}
- public function boot($debug)
+ 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 do not exists.');
- $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
+ $io->error('Class Drupal\Core\DrupalKernel does not exist.');
+ $drupal = new DrupalConsoleCore(
+ $this->drupalFinder->getComposerRoot(),
+ $this->drupalFinder->getDrupalRoot()
+ );
return $drupal->boot();
}
$_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devDesktopSettingsDir;
}
}
- $argvInputReader = new ArgvInputReader();
- $command = $argvInputReader->get('command');
+
$rebuildServicesFile = false;
if ($command=='cache:rebuild' || $command=='cr') {
$rebuildServicesFile = true;
if ($debug) {
$io->writeln('➤ Creating request');
}
- $uri = $argvInputReader->get('uri');
- if ($uri && $uri != 'http://default') {
- if (substr($uri, -1) != '/') {
- $uri .= '/';
- }
- $uri .= 'index.php';
- $request = Request::create($uri, 'GET', [], [], [], ['SCRIPT_NAME' => $this->appRoot . '/index.php']);
- } else {
- $request = Request::createFromGlobals();
- }
+
+ $_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->appRoot
+ $this->drupalFinder->getDrupalRoot()
);
if ($debug) {
$io->writeln("\r\033[K\033[1A\r<info>✔</info>");
$drupalKernel->addServiceModifier(
new DrupalServiceModifier(
- $this->root,
- $this->appRoot,
+ $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');
}
$container = $drupalKernel->getContainer();
- $container->set('console.root', $this->root);
+ $container->set(
+ 'console.root',
+ $this->drupalFinder->getComposerRoot()
+ );
AnnotationRegistry::registerLoader([$this->autoload, "loadClass"]);
$container->get('console.translator_manager')
->loadCoreLanguage(
$configuration->get('application.language'),
- $this->root
+ $this->drupalFinder->getComposerRoot()
);
- $consoleExtendConfigFile = $this->root . DRUPAL_CONSOLE .'/extend.console.config.yml';
+ $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->root.DRUPAL_CONSOLE.'/templates/',
- $this->root.DRUPAL_CONSOLE_CORE.'/templates/'
+ $this->drupalFinder->getComposerRoot().DRUPAL_CONSOLE.'/templates/',
+ $this->drupalFinder->getComposerRoot().DRUPAL_CONSOLE_CORE.'/templates/'
]
);
return $container;
} catch (\Exception $e) {
- if ($argvInputReader->get('command') == 'list') {
+ if ($command == 'list') {
$io->error($e->getMessage());
}
- $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
+ $drupal = new DrupalConsoleCore(
+ $this->drupalFinder->getComposerRoot(),
+ $this->drupalFinder->getDrupalRoot()
+ );
$container = $drupal->boot();
$container->set('class_loader', $this->autoload);
+
return $container;
}
}