addConfig example

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

#[Package('core')] class ElasticsearchExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container): void
    {
        $config = $this->processConfiguration($this->getConfiguration($configs$container)$configs);
        $this->addConfig($container$this->getAlias()$config);

        $loader = new XmlFileLoader($containernew FileLocator(__DIR__ . '/../Resources/config'));

        $loader->load('services.xml');
    }

    public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
    {
        return new Configuration();
    }

    
/** * Loads a specific configuration. * * @throws \InvalidArgumentException When provided tag is not defined in this extension */
    public function load(array $configs, ContainerBuilder $container): void
    {
        $configuration = new Configuration();

        $config = $this->processConfiguration($configuration$configs);

        $this->addConfig($container, 'storefront', $config);
        $this->registerThemeServiceAliases($config['theme']$container);
    }

    private function addConfig(ContainerBuilder $container, string $alias, array $options): void
    {
        foreach ($options as $key => $option) {
            $container->setParameter($alias . '.' . $key$option);

            if (\is_array($option)) {
                $this->addConfig($container$alias . '.' . $key$option);
            }
        }
Home | Imprint | This part of the site doesn't use cookies.