<?php

namespace AutoAdmin\Bundle\Core\DependencyInjection;


use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class AutoAdminCoreExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yaml');

        // set defaults for languages
        $locales = ['fr', 'en'];
        $defaults = [
            'locales' => $locales,
            'locales_pattern' => sprintf('(%s)', implode('|', $locales)),
            'default_locale' => 'fr',
        ];
        foreach ($defaults as $name => $value) {
            try {
                $container->getParameter($name);
            } catch (ParameterNotFoundException $exception) {
                $container->setParameter($name, $value);
            }
        }
    }
}
