2 namespace Drush\Drupal;
4 use Drush\Log\LogLevel;
5 use Drupal\Core\DrupalKernel as DrupalDrupalKernel;
6 use Symfony\Component\HttpFoundation\Request;
7 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
9 class DrupalKernel extends DrupalDrupalKernel {
10 /** @var ServiceModifierInterface[] */
11 protected $serviceModifiers = [];
16 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE, $app_root = NULL) {
17 drush_log(dt("Create from request"), LogLevel::DEBUG);
18 $kernel = new static($environment, $class_loader, $allow_dumping);
19 static::bootEnvironment();
20 $kernel->initializeSettings($request);
25 * Add a service modifier to the container builder.
27 * The container is not compiled until $kernel->boot(), so there is a chance
28 * for clients to add compiler passes et. al. before then.
30 public function addServiceModifier(ServiceModifierInterface $serviceModifier) {
31 drush_log(dt("add service modifier"), LogLevel::DEBUG);
32 $this->serviceModifiers[] = $serviceModifier;
38 protected function getContainerBuilder() {
39 drush_log(dt("get container builder"), LogLevel::DEBUG);
40 $container = parent::getContainerBuilder();
41 foreach ($this->serviceModifiers as $serviceModifier) {
42 $serviceModifier->alter($container);
47 * Initializes the service container.
49 * @return \Symfony\Component\DependencyInjection\ContainerInterface
51 protected function initializeContainer() {
52 if (empty($this->moduleList) && !$this->containerNeedsRebuild) {
53 $container_definition = $this->getCachedContainerDefinition();
54 foreach ($this->serviceModifiers as $serviceModifier) {
55 if (!$serviceModifier->check($container_definition)) {
56 $this->invalidateContainer();
61 return parent::initializeContainer();