public function resetKernel()
    {
        // Reset the kernel only if it has been initialized.
        if (LegacyKernel::hasInstance()) {
            /** @var \Closure $kernelClosure */
            $kernelClosure = $this->container->get('ezpublish_legacy.kernel');
            $this->eventDispatcher->dispatch(
                LegacyEvents::PRE_RESET_LEGACY_KERNEL,
                new PreResetLegacyKernelEvent($kernelClosure())
            );
        }

        LegacyKernel::resetInstance();
        $this->webHandler = null;
        $this->cliHandler = null;
        $this->restHandler = null;

        $this->container->set('ezpublish_legacy.kernel.lazy', null);
        $this->container->set('ezpublish_legacy.kernel_handler.web', null);
        $this->container->set('ezpublish_legacy.kernel_handler.cli', null);
        $this->container->set('ezpublish_legacy.kernel_handler.rest', null);
    }