.../Component/DependencyInjection/Container.php | 8 ++++---- .../Dumper/OptimizedPhpArrayDumper.php | 12 ++++++------ .../DependencyInjection/Dumper/PhpArrayDumper.php | 4 ++-- .../DependencyInjection/PhpArrayContainer.php | 13 ++++++------- .../Drupal/Core/DependencyInjection/Container.php | 2 +- core/lib/Drupal/Core/DrupalKernel.php | 19 +++++++++++-------- core/lib/Drupal/Core/DrupalKernelInterface.php | 2 +- .../src/Tests/DrupalKernel/DrupalKernelTest.php | 5 ++--- .../DependencyInjection/ContainerTest.php | 22 +++++++++++++++++----- .../Dumper/OptimizedPhpArrayDumperTest.php | 10 +++++----- 10 files changed, 55 insertions(+), 42 deletions(-) diff --git a/core/lib/Drupal/Component/DependencyInjection/Container.php b/core/lib/Drupal/Component/DependencyInjection/Container.php index 1640565..06d1a70 100644 --- a/core/lib/Drupal/Component/DependencyInjection/Container.php +++ b/core/lib/Drupal/Component/DependencyInjection/Container.php @@ -42,7 +42,7 @@ * * - It only allows lowercase service and parameter names, though it does only * enforce it via assertions for performance reasons. - * - The following functions, that are not part of the interface are explictly + * - The following functions, that are not part of the interface, are explicitly * not supported: getParameterBag(), isFrozen(), compile(), * getAServiceWithAnIdByCamelCase(). * - The function getServiceIds() was added as it has a use-case in core and @@ -206,14 +206,14 @@ public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_IN * @param array $definition * The service definition to create a service from. * @param string $id - * The service identifier, neccessary so it can be shared if its public. + * The service identifier, necessary so it can be shared if its public. * * @return object * The service described by the service definition. * - * @throws Symfony\Component\DependencyInjection\Exception\RuntimeException\RuntimeException + * @throws \Symfony\Component\DependencyInjection\Exception\RuntimeException * Thrown when the service is a synthetic service. - * @throws Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException * Thrown when the configurator callable is not callable. */ protected function createService(array $definition, $id) { diff --git a/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php b/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php index feca524..6aed08f 100644 --- a/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php +++ b/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php @@ -436,7 +436,7 @@ protected function dumpValue($value) { * * @param string $id * The ID of the service to get a reference for. - * @param \Symfony\Component\DependencyInjection\Reference $reference + * @param \Symfony\Component\DependencyInjection\Reference|NULL $reference * (optional) The reference object to process; needed to get the invalid * behavior value. * @@ -453,9 +453,9 @@ protected function getReferenceCall($id, Reference $reference = NULL) { // Private shared service. $definition = $this->container->getDefinition($id); if (!$definition->isPublic()) { - // The ContainerBuilder does not share a private service, - // but this means a new service is instantiated every time. - // Use a private shared service to circumvent the problem. + // The ContainerBuilder does not share a private service, but this means a + // new service is instantiated every time. Use a private shared service to + // circumvent the problem. return $this->getPrivateServiceCall($id, $definition, TRUE); } @@ -511,10 +511,10 @@ protected function getExpressionCall($expression) { } /** - * Whether this supports the machine format or not. + * Whether this supports the machine-optimized format or not. * * @return bool - * TRUE if this supports machine format, FALSE otherwise. + * TRUE if this supports machine-optimized format, FALSE otherwise. */ protected function getMachineFormat() { return TRUE; diff --git a/core/lib/Drupal/Component/DependencyInjection/Dumper/PhpArrayDumper.php b/core/lib/Drupal/Component/DependencyInjection/Dumper/PhpArrayDumper.php index 287eaa1..2f2f517 100644 --- a/core/lib/Drupal/Component/DependencyInjection/Dumper/PhpArrayDumper.php +++ b/core/lib/Drupal/Component/DependencyInjection/Dumper/PhpArrayDumper.php @@ -12,11 +12,11 @@ /** * PhpArrayDumper dumps a service container as a PHP array. * - * The format of this dumper is a human readable serialized PHP array, which is + * The format of this dumper is a human-readable serialized PHP array, which is * very similar to the YAML based format, but based on PHP arrays instead of * YAML strings. * - * It is human readable, for a machine-optimized version based on this one see + * It is human-readable, for a machine-optimized version based on this one see * \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper. * * @see \Drupal\Component\DependencyInjection\PhpArrayContainer diff --git a/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php b/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php index 69da990..7c96d07 100644 --- a/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php +++ b/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php @@ -33,11 +33,11 @@ class PhpArrayContainer extends Container { */ public function __construct(array $container_definition = array()) { if (isset($container_definition['machine_format']) && $container_definition['machine_format'] === TRUE) { - throw new InvalidArgumentException('The machine format is not supported by this class. Use a human-readable format instead, e.g. as produced by \Drupal\Component\DependencyInjection\Dumper\PhpArrayDumper.'); + throw new InvalidArgumentException('The machine-optimized format is not supported by this class. Use a human-readable format instead, e.g. as produced by \Drupal\Component\DependencyInjection\Dumper\PhpArrayDumper.'); } - // Do not call the parent's constructor as it would bail on the machine - // format. + // Do not call the parent's constructor as it would bail on the + // machine-optimized format. $this->aliases = isset($container_definition['aliases']) ? $container_definition['aliases'] : array(); $this->parameters = isset($container_definition['parameters']) ? $container_definition['parameters'] : array(); $this->serviceDefinitions = isset($container_definition['services']) ? $container_definition['services'] : array(); @@ -87,7 +87,7 @@ protected function createService(array $definition, $id) { $length = isset($definition['arguments_count']) ? $definition['arguments_count'] : count($arguments); // Optimize class instantiation for services with up to 10 parameters as - // ReflectionClass is noticeable slow. + // reflection is noticeably slow. switch ($length) { case 0: $service = new $class(); @@ -199,17 +199,16 @@ protected function resolveServicesAndParameters($arguments) { // Private services are a special flavor: In case a private service is // only used by one other service, the ContainerBuilder uses a - // Definition object as argument, which does not have a id set. + // Definition object as an argument, which does not have an ID set. // Therefore the format uses a \stdClass object to store the definition // and to be able to create the service on the fly. // // Note: When constructing a private service by hand, 'id' must be set. // // The PhpArrayDumper just uses the hash of the private service - // definition to generate a unique id. + // definition to generate a unique ID. // // @see \Drupal\Component\DependecyInjection\Dumper\OptimizedPhpArrayDumper::getPrivateServiceCall - // if ($type == 'private_service') { $id = $argument->id; diff --git a/core/lib/Drupal/Core/DependencyInjection/Container.php b/core/lib/Drupal/Core/DependencyInjection/Container.php index b58b726..a1b8d56 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Container.php +++ b/core/lib/Drupal/Core/DependencyInjection/Container.php @@ -10,7 +10,7 @@ use Drupal\Component\DependencyInjection\Container as DrupalContainer; /** - * Extends the drupal container to set the service ID on the created object. + * Extends the Drupal container to set the service ID on the created object. */ class Container extends DrupalContainer { diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index f30f32e..7ecb438 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -55,7 +55,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { * Holds the class used for dumping the container to a PHP array. * * In combination with swapping the container class this is useful to e.g. - * dump to the human writable PHP array format to debug the container + * dump to the human-readable PHP array format to debug the container * definition in an easier way. * * @var string @@ -763,7 +763,7 @@ public function updateModules(array $module_list, array $module_filenames = arra } /** - * Returns the container cache key based on environment. + * Returns the container cache key based on the environment. * * @return string * The cache key used for the service container. @@ -828,8 +828,8 @@ protected function initializeContainer() { $container = $this->compileContainer(); // Only dump the container if dumping is allowed. This is useful for - // KernelTestBase, which never wants to use the real container, but - // always the container builder. + // KernelTestBase, which never wants to use the real container, but always + // the container builder. if ($this->allowDumping) { $dumper = new $this->phpArrayDumperClass($container); $container_definition = $dumper->getArray(); @@ -839,7 +839,7 @@ protected function initializeContainer() { // The container was rebuilt successfully. $this->containerNeedsRebuild = FALSE; - // Only in case we have a container_definition, create a new class. + // Only create a new class if we have a container definition. if (isset($container_definition)) { $class = Settings::get('container_base_class', '\Drupal\Core\DependencyInjection\Container'); $container = new $class($container_definition); @@ -1247,18 +1247,21 @@ protected function getContainerBuilder() { /** * Stores the container definition in a cache. * + * @param array $container_definition + * The container definition to cache. + * * @return bool * TRUE if the container was successfully cached. */ - protected function cacheDrupalContainer($container_definition) { + protected function cacheDrupalContainer(array $container_definition) { $saved = TRUE; try { $this->bootstrapContainer->get('cache.container')->set($this->getContainerCacheKey(), $container_definition); } catch (\Exception $e) { // There is no way to get from the Cache API if the cache set was - // successful or not, hence an Exception is caught and the caller - // informed about the error condition. + // successful or not, hence an Exception is caught and the caller informed + // about the error condition. $saved = FALSE; } diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php index 6a38146..3149694 100644 --- a/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -61,7 +61,7 @@ public function getContainer(); /** * Returns the cached container definition - if any. * - * This also allows inspecting a build container for debugging purposes. + * This also allows inspecting a built container for debugging purposes. * * @return array|NULL * The cached container definition or NULL if not found in cache. diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php index ddbd6f7..e8e35a6 100644 --- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php +++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php @@ -98,8 +98,7 @@ public function testCompileDIC() { $module_list = array_keys($container->get('module_handler')->getModuleList()); $this->assertEqual(array_values($modules_enabled), $module_list); - // Now get the container another time simulating a "production" - // environment. + // Get the container another time, simulating a "production" environment. $container = $this->getTestKernel($request, NULL) ->getContainer(); @@ -129,7 +128,7 @@ public function testCompileDIC() { $this->getTestKernel($request, $modules_enabled); // Instantiate it a second time and we should not get a ContainerBuilder - // class because we are loading the container definition from the database. + // class because we are loading the container definition from cache. $kernel = $this->getTestKernel($request, $modules_enabled); $container = $kernel->getContainer(); diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 78c3be2..3802e84 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -39,12 +39,15 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { protected $containerClass; /** - * Whether the container uses the machine format or not. + * Whether the container uses the machine-optimized format or not. * * @var bool */ protected $machineFormat; + /** + * {@inheritdoc} + */ public function setUp() { $this->machineFormat = TRUE; $this->containerClass = '\Drupal\Component\DependencyInjection\Container'; @@ -54,6 +57,7 @@ public function setUp() { /** * Tests that passing a non-supported format throws an InvalidArgumentException. + * * @covers ::__construct * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException @@ -66,6 +70,7 @@ public function testConstruct() { /** * Tests that Container::getParameter() works properly. + * * @covers ::getParameter */ public function testGetParameter() { @@ -100,6 +105,7 @@ public function testGetParameterIfNotFoundBecauseNull() { /** * Tests that Container::hasParameter() works properly. + * * @covers ::hasParameter */ public function testHasParameter() { @@ -172,8 +178,9 @@ public function testGetForNonSharedService() { $this->assertNotSame($service, $service2, 'Non shared services are always re-instantiated.'); } - /** + /** * Tests that Container::get() works properly for class from parameters. + * * @covers ::get * @covers ::createService */ @@ -467,6 +474,7 @@ public function testGetForFactoryService() { /** * Tests that Container::get() for factories via class works (Symfony 2.7.0). + * * @covers ::get * @covers ::createService */ @@ -493,6 +501,7 @@ public function testGetForConfiguratorWithException() { /** * Tests that Container::get() for configurable services works. + * * @covers ::get * @covers ::createService */ @@ -515,6 +524,7 @@ public function testGetForConfigurator() { /** * Tests that private services work correctly. + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters @@ -565,6 +575,7 @@ public function testResolveServicesAndParametersForArgumentsUsingDeepArray() { /** * Tests that services that are optional work correctly. + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters @@ -597,7 +608,8 @@ public function testResolveServicesAndParametersForInvalidArgument() { * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testResolveServicesAndParametersForInvalidArguments() { - // In case the machine format is not used, we need to simulate the test failure. + // In case the machine-optimized format is not used, we need to simulate the + // test failure. if (!$this->machineFormat) { throw new \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Simulating the test failure.'); } @@ -619,6 +631,7 @@ public function testResolveServicesAndParametersForServiceInstantiatedFromParame /** * Tests that Container::initialized works correctly. + * * @covers ::initialized */ public function testInitialized() { @@ -629,6 +642,7 @@ public function testInitialized() { /** * Tests that Container::initialized works correctly for aliases. + * * @covers ::initialized */ public function testInitializedForAliases() { @@ -750,7 +764,6 @@ protected function getMockContainerDefinition() { ); // Test private services. - $private_service = array( 'class' => '\Drupal\Tests\Component\DependencyInjection\MockService', 'arguments' => $this->getCollection(array( @@ -776,7 +789,6 @@ protected function getMockContainerDefinition() { ); // Test shared private services. - $id = 'private_service_shared_1'; $services['service_using_shared_private'] = array( diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 76473a5..72af63e 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -21,7 +21,7 @@ class OptimizedPhpArrayDumperTest extends \PHPUnit_Framework_TestCase { /** - * Whether the dumper uses the machine format or not. + * Whether the dumper uses the machine-optimized format or not. * * @var bool */ @@ -84,7 +84,7 @@ public function testGetAliases($aliases, $definition_aliases) { } /** - * Data provider for test_getAliases(). + * Data provider for testGetAliases(). * * @return array[] * Returns data-set elements with: @@ -133,7 +133,7 @@ public function testGetParameters($parameters, $definition_parameters, $is_froze } /** - * Data provider for test_getParameters(). + * Data provider for testGetParameters(). * * @return array[] * Returns data-set elements with: @@ -205,7 +205,7 @@ public function testGetServiceDefinitions($services, $definition_services) { } /** - * Data provider for test_getServiceDefinitions(). + * Data provider for testGetServiceDefinitions(). * * @return array[] * Returns data-set elements with: @@ -578,7 +578,7 @@ protected function getParameterCall($name) { } -/* +/** * As Drupal Core does not ship with ExpressionLanguage component we need to * define a dummy, else it cannot be tested. */