diff --git a/core/includes/common.inc b/core/includes/common.inc index 2375b78..f7e2837 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5071,9 +5071,9 @@ function _drupal_bootstrap_code() { } /** - * Temporary BC function for scripts not using DrupalKernel. + * Temporary BC function for scripts not using HttpKernel. * - * DrupalKernel skips this and replicates it via event listeners. + * HttpKernel skips this and replicates it via event listeners. * * @see Drupal\Core\EventSubscriber\PathSubscriber; * @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber; diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php index aa73ace..b8c9f09 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php @@ -7,7 +7,23 @@ namespace Drupal\Core\DependencyInjection; +use Drupal\Core\ContentNegotiation; +use Drupal\Core\EventSubscriber\AccessSubscriber; +use Drupal\Core\EventSubscriber\FinishResponseSubscriber; +use Drupal\Core\EventSubscriber\LegacyControllerSubscriber; +use Drupal\Core\EventSubscriber\LegacyRequestSubscriber; +use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber; +use Drupal\Core\EventSubscriber\PathSubscriber; +use Drupal\Core\EventSubscriber\RequestCloseSubscriber; +use Drupal\Core\EventSubscriber\RouterListener; +use Drupal\Core\EventSubscriber\ViewSubscriber; +use Drupal\Core\ExceptionController; +use Drupal\Core\LegacyUrlMatcher; use Symfony\Component\DependencyInjection\ContainerBuilder as BaseContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpKernel\EventListener\ExceptionListener; /** * Drupal's dependency injection container. @@ -27,5 +43,51 @@ class ContainerBuilder extends BaseContainerBuilder { // Register the default language content. $this->register(LANGUAGE_TYPE_CONTENT, 'Drupal\\Core\\Language\\Language'); + + // Register the kernel services. + $this->setDefinition('drupal.dispatcher', new Definition('Symfony\Component\EventDispatcher\EventDispatcher')) + ->setFactoryClass('Drupal\Core\DependencyInjection\ContainerBuilder') + ->setFactoryMethod('getKernelEventDispatcher'); + $this->register('drupal.resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver'); + $this->register('drupal.kernel', 'Symfony\Component\HttpKernel\HttpKernel') + ->addArgument(new Reference('drupal.dispatcher')) + ->addArgument(new Reference('drupal.resolver')); + } + + /** + * Creates an EventDispatcher for the HttpKernel. Factory method. + * + * @return Symfony\Component\EventDispatcher\EventDispatcher + * An EventDispatcher with the default listeners attached to it. + */ + public static function getKernelEventDispatcher() { + $dispatcher = new EventDispatcher(); + + $matcher = new LegacyUrlMatcher(); + $dispatcher->addSubscriber(new RouterListener($matcher)); + + $negotiation = new ContentNegotiation(); + + // @todo Make this extensible rather than just hard coding some. + // @todo Add a subscriber to handle other things, too, like our Ajax + // replacement system. + $dispatcher->addSubscriber(new ViewSubscriber($negotiation)); + $dispatcher->addSubscriber(new AccessSubscriber()); + $dispatcher->addSubscriber(new MaintenanceModeSubscriber()); + $dispatcher->addSubscriber(new PathSubscriber()); + $dispatcher->addSubscriber(new LegacyRequestSubscriber()); + $dispatcher->addSubscriber(new LegacyControllerSubscriber()); + $dispatcher->addSubscriber(new FinishResponseSubscriber()); + $dispatcher->addSubscriber(new RequestCloseSubscriber()); + + // Some other form of error occured that wasn't handled by another kernel + // listener. That could mean that it's a method/mime-type/error combination + // that is not accounted for, or some other type of error. Either way, treat + // it as a server-level error and return an HTTP 500. By default, this will + // be an HTML-type response because that's a decent best guess if we don't + // know otherwise. + $dispatcher->addSubscriber(new ExceptionListener(array(new ExceptionController($negotiation), 'execute'))); + + return $dispatcher; } } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php deleted file mode 100644 index 7361a82..0000000 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ /dev/null @@ -1,65 +0,0 @@ -matcher = new LegacyUrlMatcher(); - $this->dispatcher->addSubscriber(new RouterListener($this->matcher)); - - $negotiation = new ContentNegotiation(); - - // @todo Make this extensible rather than just hard coding some. - // @todo Add a subscriber to handle other things, too, like our Ajax - // replacement system. - $this->dispatcher->addSubscriber(new ViewSubscriber($negotiation)); - $this->dispatcher->addSubscriber(new AccessSubscriber()); - $this->dispatcher->addSubscriber(new MaintenanceModeSubscriber()); - $this->dispatcher->addSubscriber(new PathSubscriber()); - $this->dispatcher->addSubscriber(new LegacyRequestSubscriber()); - $this->dispatcher->addSubscriber(new LegacyControllerSubscriber()); - $this->dispatcher->addSubscriber(new FinishResponseSubscriber()); - $this->dispatcher->addSubscriber(new RequestCloseSubscriber()); - - // Some other form of error occured that wasn't handled by another kernel - // listener. That could mean that it's a method/mime-type/error - // combination that is not accounted for, or some other type of error. - // Either way, treat it as a server-level error and return an HTTP 500. - // By default, this will be an HTML-type response because that's a decent - // best guess if we don't know otherwise. - $this->dispatcher->addSubscriber(new ExceptionListener(array(new ExceptionController($this, $negotiation), 'execute'))); - } -} diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php index b163395..fc27554 100644 --- a/core/lib/Drupal/Core/ExceptionController.php +++ b/core/lib/Drupal/Core/ExceptionController.php @@ -10,7 +10,7 @@ namespace Drupal\Core; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\Exception\FlattenException; /** @@ -19,15 +19,6 @@ use Symfony\Component\HttpKernel\Exception\FlattenException; class ExceptionController { /** - * The kernel that spawned this controller. - * - * We will use this to fire subrequests as needed. - * - * @var Symfony\Component\HttpKernel\HttpKernelInterface - */ - protected $kernel; - - /** * The content negotiation library. * * @var Drupal\Core\ContentNegotiation @@ -37,15 +28,11 @@ class ExceptionController { /** * Constructor. * - * @param Symfony\Component\HttpKernel\HttpKernelInterface $kernel - * The kernel that spawned this controller, so that it can be reused - * for subrequests. * @param Drupal\Core\ContentNegotiation $negotiation * The content negotiation library to use to determine the correct response * format. */ - public function __construct(HttpKernelInterface $kernel, ContentNegotiation $negotiation) { - $this->kernel = $kernel; + public function __construct(ContentNegotiation $negotiation) { $this->negotiation = $negotiation; } @@ -119,7 +106,7 @@ class ExceptionController { drupal_static_reset('menu_set_active_trail'); menu_reset_static_cache(); - $response = $this->kernel->handle($subrequest, DrupalKernel::SUB_REQUEST); + $response = drupal_container()->get('drupal.kernel')->handle($subrequest, HttpKernel::SUB_REQUEST); $response->setStatusCode(403, 'Access denied'); } else { @@ -184,7 +171,7 @@ class ExceptionController { drupal_static_reset('menu_set_active_trail'); menu_reset_static_cache(); - $response = $this->kernel->handle($subrequest, HttpKernelInterface::SUB_REQUEST); + $response = drual_container()->get('drupal.kernel')->handle($subrequest, HttpKernel::SUB_REQUEST); $response->setStatusCode(404, 'Not Found'); } else { diff --git a/index.php b/index.php index 2f05bb3..4251a3a 100644 --- a/index.php +++ b/index.php @@ -11,10 +11,7 @@ * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory. */ -use Drupal\Core\DrupalKernel; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\HttpKernel\Controller\ControllerResolver; /** * Root directory of Drupal installation. @@ -39,9 +36,6 @@ request($request); // @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber; drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); -$dispatcher = new EventDispatcher(); -$resolver = new ControllerResolver(); - -$kernel = new DrupalKernel($dispatcher, $resolver); +$kernel = drupal_container()->get('drupal.kernel'); $response = $kernel->handle($request)->prepare($request)->send(); $kernel->terminate($request, $response);