diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php index ab89658f2da223a55a16e902abdce2923e61ffcf..479fbd54c6f6edb6955a775a61f1d9559de21709 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php @@ -13,6 +13,8 @@ /** * Adds services tagged "needs_destruction" to the "kernel_destruct_subscriber" * service. + * + * @see \Drupal\Core\DestructableInterface */ class RegisterServicesForDestructionPass implements CompilerPassInterface { diff --git a/core/lib/Drupal/Core/DestructableInterface.php b/core/lib/Drupal/Core/DestructableInterface.php index e06c6eca006ad85cc73fe0c9fd39caf326623a29..abfec7aea178df8d4cd92c97ede02581884b50bf 100644 --- a/core/lib/Drupal/Core/DestructableInterface.php +++ b/core/lib/Drupal/Core/DestructableInterface.php @@ -9,6 +9,13 @@ /** * The interface for services that need explicit destruction. + * + * This is useful for services that need to perform additional tasks to + * finalize operations or clean up after the response is sent and before the + * service is terminated. + * + * Services using this interface need to be registered with the + * "needs_destruction" tag. */ interface DestructableInterface { diff --git a/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php index 7cedb1c94de2acb0256e4d8bd604c4ad85df5cc6..9c3cfae197630a17ae29bfd06af17fbe204ec107 100644 --- a/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php @@ -14,6 +14,8 @@ /** * Destructs services that are initiated and tagged with "needs_destruction". + * + * @see \Drupal\Core\DestructableInterface */ class KernelDestructionSubscriber implements EventSubscriberInterface, ContainerAwareInterface { diff --git a/core/modules/system/core.api.php b/core/modules/system/core.api.php index 14c894aa991809bf912cafb66e305475db76f5e6..dacffed6d017f9dc3213e9c6a5f0abaf03ac9826 100644 --- a/core/modules/system/core.api.php +++ b/core/modules/system/core.api.php @@ -2152,7 +2152,8 @@ function hook_config_schema_info_alter(&$definitions) { * for more information. * - needs_destruction: Indicates that a destruct() method needs to be called * at the end of a request to finalize operations, if this service was - * instantiated. + * instantiated. Services should implement \Drupal\Core\DestructableInterface + * in this case. * * Creating a tag for a service does not do anything on its own, but tags * can be discovered or queried in a compiler pass when the container is built,