diff --git a/core/lib/Drupal/Core/DependencyInjection/Container.php b/core/lib/Drupal/Core/DependencyInjection/Container.php index 5554224..3c8b631 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Container.php +++ b/core/lib/Drupal/Core/DependencyInjection/Container.php @@ -44,10 +44,10 @@ * - 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 - * not supported: - * getParameterBag(), isFrozen(), compile(), - * getAServiceWithAnIdByCamelCase(). - * - getServiceIds() was added as it has a use-case in core and contrib. + * not supported: getParameterBag(), isFrozen(), compile(), + * getAServiceWithAnIdByCamelCase(). + * - The function getServiceIds() was added as it has a use-case in core and + * contrib. * - Scopes are explicitly not allowed, because Symfony 2.8 has deprecated * them and they will be removed in Symfony 3.0. * - Synchronized services are explicitly not supported, because Symfony 2.8 has @@ -106,7 +106,7 @@ class Container implements IntrospectableContainerInterface { protected $loading = array(); /** - * Can the container parameters still be changed. + * Whether the container parameters can still be changed. * * For testing purposes the container needs to be changed. * @@ -169,8 +169,8 @@ public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_IN } // In case something else than ContainerInterface::NULL_ON_INVALID_REFERENCE - // is used, the actual wanted behavior is to re-try getting the service at - // a later point. + // is used, the actual wanted behavior is to re-try getting the service at a + // later point. if (!$definition) { return; } @@ -258,7 +258,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. + // ReflectionClass is noticeably slow. switch ($length) { case 0: $service = new $class(); @@ -428,11 +428,10 @@ public function initialized($id) { * @return array * The resolved arguments. * - * @throws RuntimeException + * @throws \Symfony\Component\DependencyInjection\Exception\RuntimeException * If a parameter/service could not be resolved. */ protected function resolveServicesAndParameters($arguments) { - // Check if this collection needs to be resolved. if ($arguments instanceof \stdClass) { if ($arguments->type !== 'collection') { diff --git a/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php b/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php index 1df56c2..d433375 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php +++ b/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php @@ -20,20 +20,20 @@ /** * OptimizedPhpArrayDumper dumps a service container as a serialized PHP array. * - * The format of this dumper is very similar to the ContainerBuilder based - * format, but based on PHP arrays and \stdClass objects instead of rich value - * objects for performance reasons. + * The format of this dumper is very similar to the internal structure of the + * ContainerBuilder, but based on PHP arrays and \stdClass objects instead of + * rich value objects for performance reasons. * * By removing the abstraction and optimizing some cases like deep collections, - * less classes need to be loaded, less function calls need to be executed and - * less run time checks need to be made. + * fewer classes need to be loaded, fewer function calls need to be executed and + * fewer run time checks need to be made. * * In addition to that, this container dumper treats private services as * strictly private with their own private services storage, whereas in the - * Symfony service container builder and PHP dumper shared private services can + * Symfony service container builder and PHP dumper, shared private services can * still be retrieved via get() from the container. * - * It is machine readable, for a human readable version based on this one see + * It is machine-optimized, for a human-readable version based on this one see * \Drupal\Core\DependencyInjection\Dumper\PhpArrayDumper. * * @see \Drupal\Core\DependecyInjection\Container @@ -437,8 +437,8 @@ protected function dumpValue($value) { * @param string $id * The ID of the service to get a reference for. * @param \Symfony\Component\DependencyInjection\Reference $reference - * (optional) The reference object to process, needed to get the invalid - * behavior. + * (optional) The reference object to process; needed to get the invalid + * behavior value. * * @return string|\stdClass * A suitable representation of the service reference. @@ -463,7 +463,7 @@ protected function getReferenceCall($id, Reference $reference = NULL) { } /** - * Gets a service reference for an id in a suitable PHP array format. + * Gets a service reference for an ID in a suitable PHP array format. * * @param string $id * The ID of the service to get a reference for. diff --git a/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php b/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php index 47349c1..c22580b 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php +++ b/core/lib/Drupal/Core/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 very similar to the YAML based format, but - * based on PHP arrays instead of YAML strings. + * 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\Core\DependencyInjection\Dumper\OptimizedPhpArrayDumper. * * @see \Drupal\Core\DependencyInjection\PhpArrayContainer diff --git a/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php b/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php index ff2e3ce..4ca94fa 100644 --- a/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php +++ b/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php @@ -36,7 +36,7 @@ public function __construct(array $container_definition = array()) { throw new InvalidArgumentException('The machine format is not supported by this class. Use a human-readable format instead, e.g. as produced by \Drupal\Core\DependencyInjection\Dumper\PhpArrayDumper.'); } - // Do not call the parents constructor as it would bail on the machine + // Do not call the parent's constructor as it would bail on the machine // format. $this->aliases = isset($container_definition['aliases']) ? $container_definition['aliases'] : array(); $this->parameters = isset($container_definition['parameters']) ? $container_definition['parameters'] : array(); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 6514d9f..2dd59ce 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -472,6 +472,19 @@ public function getContainer() { /** * {@inheritdoc} */ + public function getCachedContainerDefinition() { + $cache = $this->bootstrapContainer->get('cache.container')->get($this->getContainerCacheKey()); + + if ($cache) { + return $cache->data; + } + + return NULL; + } + + /** + * {@inheritdoc} + */ public function loadLegacyIncludes() { require_once $this->root . '/core/includes/common.inc'; require_once $this->root . '/core/includes/database.inc'; @@ -751,7 +764,7 @@ public function updateModules(array $module_list, array $module_filenames = arra * The cache key used for the service container. */ protected function getContainerCacheKey() { - $parts = array('service_container', $this->environment, hash('crc32b', \Drupal::VERSION . Settings::get('deployment_identifier'))); + $parts = array('service_container', $this->environment, \Drupal::VERSION, Settings::get('deployment_identifier')); return implode(':', $parts); } @@ -792,12 +805,9 @@ protected function initializeContainer() { } // If the module list hasn't already been set in updateModules and we are - // not forcing a rebuild, then try and load the container from the disk. + // not forcing a rebuild, then try and load the container from the cache. if (empty($this->moduleList) && !$this->containerNeedsRebuild) { - $cache = $this->bootstrapContainer->get('cache.container')->get($this->getContainerCacheKey()); - if ($cache) { - $container_definition = $cache->data; - } + $container_definition = $this->getCachedContainerDefinition(); } if (!isset($container_definition)) { diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php index 892952a..48fef27 100644 --- a/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -58,6 +58,16 @@ public function getServiceProviders($origin); public function getContainer(); /** + * Returns the cached container definition - if any. + * + * This also allows inspecting a build container for debugging purposes. + * + * @return array|NULL + * The cached container definition or NULL if not found in cache. + */ + public function getCachedContainerDefinition(); + + /** * Set the current site path. * * @param string $path diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 10980d7..ca8cf98 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -64,7 +64,6 @@ public function testConstruct() { $container = new $this->containerClass($container_definition); } - /** * Tests that Container::getParameter() works properly. * @covers ::getParameter @@ -1031,7 +1030,7 @@ protected function getPrivateServiceCall($id, $service_definition, $shared = FAL } /** - * Helper function to return a machine readable collection. + * Helper function to return a machine-optimized collection. */ protected function getCollection($collection, $resolve = TRUE) { return (object) array( diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index a4a736c..62c9a35 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -554,7 +554,7 @@ protected function getPrivateServiceCall($id, $service_definition, $shared = FAL } /** - * Helper function to return a machine readable collection. + * Helper function to return a machine-optimized collection. */ protected function getCollection($collection, $resolve = TRUE) { return (object) array( diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArrayContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArrayContainerTest.php index 5e6e276..1fad50d 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArrayContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArrayContainerTest.php @@ -45,7 +45,7 @@ protected function getParameterCall($name) { } /** - * Helper function to return a machine readable '@notation'. + * Helper function to return a machine-optimized '@notation'. */ protected function getCollection($collection, $resolve = TRUE) { return $collection;