Created
December 24, 2021 19:52
-
-
Save mglaman/07ee8d987eee0d4dc73505df05959d3a to your computer and use it in GitHub Desktop.
in memory bootstrapped Drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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