From e665805ccee0c28c21d613c87ff0d2c23f9f4b7c Mon Sep 17 00:00:00 2001 From: Katherine Bailey Date: Wed, 11 Jul 2012 16:47:37 -0700 Subject: [PATCH] Various coding standards fixes and other minor changes in response to Crell's latest patch review --- .../Core/{DrupalBundle.php => CoreBundle.php} | 11 ++++++---- .../Compiler/RegisterKernelListenersPass.php | 3 ++- .../DependencyInjection/ContainerBuilder.php | 17 ++++++---------- core/lib/Drupal/Core/DrupalKernel.php | 20 +++++++------------ 4 files changed, 22 insertions(+), 29 deletions(-) rename core/lib/Drupal/Core/{DrupalBundle.php => CoreBundle.php} (91%) diff --git a/core/lib/Drupal/Core/DrupalBundle.php b/core/lib/Drupal/Core/CoreBundle.php similarity index 91% rename from core/lib/Drupal/Core/DrupalBundle.php rename to core/lib/Drupal/Core/CoreBundle.php index acd16279b1f..04ec59f3e8e 100644 --- a/core/lib/Drupal/Core/DrupalBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -9,10 +9,14 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\Compiler\PassConfig; -class DrupalBundle extends Bundle +/** + * This is where Drupal core registers all of its services to the Dependency + * Injection Container. Modules wishing to register services to the container + * should extend Symfony's Bundle class directly, not this class. + */ +class CoreBundle extends Bundle { - public function build(ContainerBuilder $container) - { + public function build(ContainerBuilder $container) { $container->register('dispatcher', 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher') ->addArgument(new Reference('service_container')); $container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver'); @@ -57,6 +61,5 @@ class DrupalBundle extends Bundle // Add a compiler pass for registering event subscribers. $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); - } } diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterKernelListenersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterKernelListenersPass.php index 79fbe7cdbc3..55343dc3b00 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterKernelListenersPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterKernelListenersPass.php @@ -7,6 +7,7 @@ namespace Drupal\Core\DependencyInjection\Compiler; +use ReflectionClass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -25,7 +26,7 @@ class RegisterKernelListenersPass implements CompilerPassInterface // We must assume that the class value has been correcly filled, even if the service is created by a factory $class = $container->getDefinition($id)->getClass(); - $refClass = new \ReflectionClass($class); + $refClass = new ReflectionClass($class); $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; if (!$refClass->implementsInterface($interface)) { throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface)); diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php index fe4541fc98d..75a31bf82da 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php @@ -18,21 +18,16 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ContainerBuilder extends BaseContainerBuilder { - public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) - { - if (!isset($this->compiler) || null === $this->compiler) { - $this->compiler = new Compiler(); - } + public function __construct() { + parent::__construct(); + $this->compiler = new Compiler(); + } + public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) { $this->compiler->addPass($pass, $type); } - public function compile() - { - if (null === $this->compiler) { - $this->compiler = new Compiler(); - } - + public function compile() { $this->compiler->compile($this); $this->parameterBag->resolve(); // TODO: The line below is commented out because there is code that calls diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 283e59cf532..0c19a6bdc7a 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -7,7 +7,7 @@ namespace Drupal\Core; -use Drupal\Core\DrupalBundle; +use Drupal\Core\CoreBundle; use Symfony\Component\HttpKernel\Kernel; use Drupal\Core\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\Loader\LoaderInterface; @@ -18,10 +18,9 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class DrupalKernel extends Kernel { - public function registerBundles() - { + public function registerBundles() { $bundles = array( - new DrupalBundle(), + new CoreBundle(), ); // Rather than bootstrapping to a higher phase prior to booting the Kernel, which @@ -47,8 +46,7 @@ class DrupalKernel extends Kernel { /** * Initializes the service container. */ - protected function initializeContainer() - { + protected function initializeContainer() { $this->container = $this->buildContainer(); $this->container->set('kernel', $this); drupal_container($this->container); @@ -59,8 +57,7 @@ class DrupalKernel extends Kernel { * * @return ContainerBuilder The compiled service container */ - protected function buildContainer() - { + protected function buildContainer() { $container = $this->getContainerBuilder(); if ($bootstrap_container = drupal_container()) { @@ -73,19 +70,16 @@ class DrupalKernel extends Kernel { return $container; } - /** * Gets a new ContainerBuilder instance used to build the service container. * * @return ContainerBuilder */ - protected function getContainerBuilder() - { + protected function getContainerBuilder() { return new ContainerBuilder(new ParameterBag($this->getKernelParameters())); } - public function registerContainerConfiguration(LoaderInterface $loader) - { + public function registerContainerConfiguration(LoaderInterface $loader) { // We have to define this method because it's not defined in the base class // but is part of the KernelInterface interface. However, the LoaderInterface // class is part of the config component, which we are not using, so this