private function getKernelObject($kernel): KernelInterface
    {
        if ($kernel instanceof KernelInterface) {
            return $kernel;
        } elseif (is_callable($kernel)) {
            return new CallbackKernel($kernel);
        }

        throw new \InvalidArgumentException('Kernel must be callable or an instance of KernelInterface');
    }