Q:

Access kernel into a bundle extension class

I try to enhance one of my bundle Extension which load my YAML configuration files and I have to access the kernel class to use method locateResource().
The goal is to load resources files without using :
__DIR__ . '/../Resources/config'

Extension class looks like this :
class InnovaPathExtension extends Extension
{
    /**
     * Base path to the config directory of the bundle
     * @var unknown
     */
    const CONFIG_PATH = '@InnovaPathBundle/Resources/config/';

    /**
     * List of needed config files
     * @var array
     */
    protected $filesToLoad = array (
        // Services
        'services/services.yml',
        'services/listeners.yml',
        'services/managers.yml',
        'services/controllers.yml',

        // Parameters
        'parameters.yml',
    );

    /**
     * @see \Symfony\Component\DependencyInjection\Extension\ExtensionInterface::load()
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        foreach ($this->filesToLoad as $file) {
            // Check if resources exists
            try {
                $resource = static::CONFIG_PATH . $file;
                $filePath = $container->get('kernel')->locateResource($resource);
            } catch (\InvalidArgumentException $e) {
                throw new \InvalidArgumentException(sprintf('Unable to load "%s"', $resource), 0, $e);
            }

            // TODO : Load resource
        }

        return $this;
    }
}

Instruction $container->get('kernel') throws an Exception 'The service definition "kernel" does not exist.'
If I check all services registered with $container->getServiceIds(), the only one I found is service_container.
Not a problem, I grab the service container and check services with $container->get('service_container')->getServiceIds()... And I only get one service : service_container.
I can't understand why... Is it DI-CEPTION ?

A:

Recommended way is:
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;

public function load(array $configs, ContainerBuilder $container)
{
    $loader = new YamlFileLoader(
        $container,
        new FileLocator(__DIR__.'/../Resources/config')
    );

    foreach ($this->filesToLoad as $file) {
        $loader->load($file);
    }
}

Other ways will not be recommended.
See http://symfony.com/doc/current/cookbook/bundles/extension.html#loading-external-configuration-resources

