diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index dba824f..01e5b34 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -7,13 +7,11 @@ namespace Drupal\Core; -use Drupal\Core\DependencyInjection\Compiler\RegisterKernelListenersPass; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Scope; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\Compiler\PassConfig; /** * Bundle class for mandatory core services. @@ -22,12 +20,19 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; * Injection Container. Modules wishing to register services to the container * should extend Symfony's Bundle class directly, not this class. */ -class CoreBundle extends Bundle -{ +class CoreBundle extends Bundle { + + /** + * Implements Symfony\Component\HttpKernel\Bundle\BundleInterface::build(). + */ public function build(ContainerBuilder $container) { - // Add a 'request' scope for services that depend on the Request object. + // The 'request' scope and service enable services to depend on the Request + // object and get reconstructed when the request object changes (e.g., + // during a subrequest). $container->addScope(new Scope('request')); + $container->register('request', 'Symfony\Component\HttpFoundation\Request') + ->setSynthetic(TRUE); $container->register('dispatcher', 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher') ->addArgument(new Reference('service_container')); @@ -36,6 +41,27 @@ class CoreBundle extends Bundle ->addArgument(new Reference('dispatcher')) ->addArgument(new Reference('service_container')) ->addArgument(new Reference('resolver')); + $container->register('language_manager', 'Drupal\Core\Language\LanguageManager') + ->addArgument(new Reference('request')) + ->setScope('request'); + + // @todo Replace below lines with the commented out block below it when it's + // performant to do so: http://drupal.org/node/1706064. + $dispatcher = $container->get('dispatcher'); + $matcher = new \Drupal\Core\LegacyUrlMatcher(); + $content_negotation = new \Drupal\Core\ContentNegotiation(); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\RouterListener($matcher)); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\ViewSubscriber($content_negotation)); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\AccessSubscriber()); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber()); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\PathSubscriber()); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\LegacyRequestSubscriber()); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\LegacyControllerSubscriber()); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\FinishResponseSubscriber()); + $dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\RequestCloseSubscriber()); + $container->set('content_negotiation', $content_negotation); + $dispatcher->addSubscriber(\Drupal\Core\ExceptionController::getExceptionListener($container)); + /* $container->register('matcher', 'Drupal\Core\LegacyUrlMatcher'); $container->register('router_listener', 'Drupal\Core\EventSubscriber\RouterListener') ->addArgument(new Reference('matcher')) @@ -73,13 +99,9 @@ class CoreBundle extends Bundle ->addArgument(new Reference('service_container')) ->setFactoryClass('Drupal\Core\ExceptionController') ->setFactoryMethod('getExceptionListener'); - $container->register('request', 'Symfony\Component\HttpFoundation\Request') - ->setSynthetic(TRUE); - $container->register('language_manager', 'Drupal\Core\Language\LanguageManager') - ->addArgument(new Reference('request')) - ->setScope('request'); // Add a compiler pass for registering event subscribers. $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); + */ } } diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php deleted file mode 100644 index 0bc4d67..0000000 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ /dev/null @@ -1,45 +0,0 @@ -container = $this->buildContainer(); + $this->container->set('kernel', $this); drupal_container($this->container); } @@ -52,7 +69,7 @@ class DrupalKernel extends Kernel { /** * Builds the service container. * - * @return ContainerBuilder The compiled service container + * @return ContainerBuilder The fully built service container. */ protected function buildContainer() { $container = $this->getContainerBuilder(); @@ -64,29 +81,11 @@ class DrupalKernel extends Kernel { foreach ($this->bundles as $bundle) { $bundle->build($container); } - $container->compile(); - return $container; - } - /** - * Gets a new ContainerBuilder instance used to build the service container. - * - * @return ContainerBuilder - */ - protected function getContainerBuilder() { - return new ContainerBuilder(new ParameterBag($this->getKernelParameters())); - } + // @todo Compile the container: http://drupal.org/node/1706064. + //$container->compile(); - /** - * Overrides and eliminates this method from the parent class. Do not use. - * - * This method is part of the KernelInterface interface, but takes an object - * implementing LoaderInterface as its only parameter. This is part of the - * Config compoment from Symfony, which is not provided by Drupal core. - * - * Modules wishing to provide an extension to this class which uses this - * method are responsible for ensuring the Config component exists. - */ - public function registerContainerConfiguration(LoaderInterface $loader) { + return $container; } + } diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 3c3126d..d989e69 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -7,7 +7,6 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Language\LanguageManager; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -17,12 +16,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; */ class FinishResponseSubscriber implements EventSubscriberInterface { - protected $language_manager; - - public function __construct(LanguageManager $language_manager) { - $this->language_manager = $language_manager; - } - /** * Sets extra headers on successful responses. * @@ -37,7 +30,10 @@ class FinishResponseSubscriber implements EventSubscriberInterface { $response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', false); // Set the Content-language header. - $response->headers->set('Content-language', $this->language_manager->getLanguage(LANGUAGE_TYPE_INTERFACE)->langcode); + // @todo Receive the LanguageManager object as a constructor argument when + // the dependency injection container allows for it performantly: + // http://drupal.org/node/1706064. + $response->headers->set('Content-language', language_manager(LANGUAGE_TYPE_INTERFACE)->langcode); // Because pages are highly dynamic, set the last-modified time to now // since the page is in fact being regenerated right now. diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php index bd940d3..c3040d7 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php @@ -7,7 +7,6 @@ namespace Drupal\language\Tests; -use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; diff --git a/core/modules/system/tests/modules/bundle_test/bundle_test.module b/core/modules/system/tests/modules/bundle_test/bundle_test.module index 5f30b8f..b1f443c 100644 --- a/core/modules/system/tests/modules/bundle_test/bundle_test.module +++ b/core/modules/system/tests/modules/bundle_test/bundle_test.module @@ -1,5 +1,8 @@ register('bundle_test_class', 'Drupal\bundle_test\TestClass') ->addTag('kernel.event_subscriber'); + + // @todo Remove when the 'kernel.event_subscriber' tag above is made to + // work: http://drupal.org/node/1706064. + $container->get('dispatcher')->addSubscriber($container->get('bundle_test_class')); } }