Is there a way to access the kernel from inside a compiler pass? I've tried this:
...
public function process(ContainerBuilder $container)
{
$kernel = $container->get('kernel');
}
...
This throws an error. Is there another way to do it?
As far as I can tell, Kernel isn't available anywhere in a CompilerPass, by default.
But you can add it in by doing this:
In your AppKernel, pass $this to the bundle the compiler pass is in.
What samanime recommends works if you need to whole kernel.
If you are just interested in some values the kernel contains, it might be sufficient to just use the parameters set by symfony.
Here is a list of available ones:
For instance, the
kernel.bundles
contains a list of all registered bundles in the format[bundle => class]
.PS: I fetched this list using the following compiler pass: