Change record status: 
Project: 
Introduced in branch: 
11.x
Introduced in version: 
11.5.0
Description: 

Container loading, dumping, and invalidation have been extracted from DrupalKernel into the new \Drupal\Core\DependencyInjection\ContainerStorageInterface. Several DrupalKernel methods, properties, and the $phpArrayDumperClass property are deprecated. New classes and an updated PhpContainer base class are introduced.

New ContainerStorageInterface and implementations

\Drupal\Core\DependencyInjection\ContainerStorageInterface is the new abstraction for container persistence. Three implementations are provided:

  • ContainerStorage\CacheContainerStorage — stores the container as a serialised PHP array in cache.container. This is the legacy behaviour, now encapsulated in its own class.
  • ContainerStorage\PhpDumperContainerStorage — compiles the container via Symfony's PhpDumper into a uniquely-named PHP class stored in PhpStorage. The class name is derived from an xxh128 hash of the generated code so that concurrent requests during a rebuild never load a stale class.
  • ContainerStorage\NullContainerStorage — always returns NULL from load() and returns the ContainerBuilder unchanged from dump(). Used by InstallerKernel, UpdateKernel, and TestKernel where persistent storage is not wanted.

New PhpContainer base class

\Drupal\Core\DependencyInjection\PhpContainer is the new base class for containers compiled by PhpDumperContainerStorage.

Deprecated DrupalKernel members

The following are deprecated in Drupal 11.4.0 and removed in Drupal 13.0.0:

DrupalKernel::$phpArrayDumperClass
Previously used to swap the dumper class used when serialising the container to the cache bin. Override the container_storage.cache service in the bootstrap container definition, or pass a custom $dumperClass as the third constructor argument of CacheContainerStorage, instead.
DrupalKernel::getCachedContainerDefinition()
Previously returned the raw PHP array definition from the cache bin. Use ContainerStorageInterface::load() instead.
DrupalKernel::getContainerCacheKey()
Previously returned the full cache key string (prefix + identifier). Use the new protected DrupalKernel::getContainerIdentifier() instead. The full key with its prefix is now an internal detail of each ContainerStorageInterface implementation.
DrupalKernel::cacheDrupalContainer()
Previously wrote the container definition directly to the cache bin. Use ContainerStorageInterface::dump() instead.
Impacts: 
Module developers