Skip to content

Commit

Permalink
Fix hechoendrupal#3264: Drupal::boot method causes 404 errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Apr 12, 2017
1 parent 9d2012b commit a6f4538
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/Bootstrap/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public function __construct($autoload, $root, $appRoot)
$this->appRoot = $appRoot;
}

public function boot($debug = false)
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 (!class_exists('Drupal\Core\DrupalKernel')) {
$io->error('Class Drupal\Core\DrupalKernel does not exist.');
Expand All @@ -57,8 +60,7 @@ public function boot($debug = false)
$_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devDesktopSettingsDir;
}
}
$argvInputReader = new ArgvInputReader();
$command = $argvInputReader->get('command');

$rebuildServicesFile = false;
if ($command=='cache:rebuild' || $command=='cr') {
$rebuildServicesFile = true;
Expand All @@ -67,12 +69,20 @@ public function boot($debug = false)
if ($debug) {
$io->writeln('➤ Creating request');
}
$uri = $argvInputReader->get('uri');
if (substr($uri, -1) != '/') {
$uri .= '/';
}
$uri .= 'index.php';
$request = Request::create($uri, 'GET', [], [], [], ['SCRIPT_NAME' => '/index.php']);

$_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->appRoot . '/index.php';
$request = Request::createFromGlobals();

var_export($_SERVER);

if ($debug) {
$io->writeln("\r\033[K\033[1A\r<info>✔</info>");
Expand Down Expand Up @@ -141,7 +151,7 @@ public function boot($debug = false)

return $container;
} catch (\Exception $e) {
if ($argvInputReader->get('command') == 'list') {
if ($command == 'list') {
$io->error($e->getMessage());
}
$drupal = new DrupalConsoleCore($this->root, $this->appRoot);
Expand Down

0 comments on commit a6f4538

Please sign in to comment.