Skip to content

Instantly share code, notes, and snippets.

@mglaman
Created December 24, 2021 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mglaman/07ee8d987eee0d4dc73505df05959d3a to your computer and use it in GitHub Desktop.
Save mglaman/07ee8d987eee0d4dc73505df05959d3a to your computer and use it in GitHub Desktop.
in memory bootstrapped Drupal
<?php declare(strict_types=1);
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
return;
}
$autoloader = require __DIR__ . '/vendor/autoload.php';
$drupalRoot = __DIR__ . '/vendor/drupal';
Database::addConnectionInfo('default', 'default', [
'driver' => 'sqlite',
'database' => ':memory:',
]);
chdir($drupalRoot);
// Initialize empty settings.
Settings::initialize($drupalRoot, __DIR__, $autoloader);
// Cause the static \Drupal class to become populated with a container.
DrupalKernel::bootEnvironment($drupalRoot);
$kernel = new DrupalKernel('prod', $autoloader, TRUE, $drupalRoot);
$kernel->setSitePath(__DIR__);
$kernel->boot();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment