By alexpott on
Change record status:
Draft (View all draft change records)
Project:
Introduced in branch:
11.x
Introduced in version:
11.5.0
Issue links:
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 incache.container. This is the legacy behaviour, now encapsulated in its own class. -
ContainerStorage\PhpDumperContainerStorage— compiles the container via Symfony'sPhpDumperinto a uniquely-named PHP class stored inPhpStorage. The class name is derived from anxxh128hash of the generated code so that concurrent requests during a rebuild never load a stale class. -
ContainerStorage\NullContainerStorage— always returnsNULLfromload()and returns theContainerBuilderunchanged fromdump(). Used byInstallerKernel,UpdateKernel, andTestKernelwhere 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.cacheservice in the bootstrap container definition, or pass a custom$dumperClassas the third constructor argument ofCacheContainerStorage, 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 eachContainerStorageInterfaceimplementation. DrupalKernel::cacheDrupalContainer()- Previously wrote the container definition directly to the cache bin. Use
ContainerStorageInterface::dump()instead.
Impacts:
Module developers