nexylan/slack-bundle

View on GitHub
src/DependencyInjection/NexySlackExtension.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

/*
 * This file is part of the Nexylan packages.
 *
 * (c) Nexylan SAS <contact@nexylan.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nexy\SlackBundle\DependencyInjection;

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

final class NexySlackExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container): void
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $container->setParameter('nexy_slack.endpoint', $config['endpoint']);
        $container->setAlias('nexy_slack.http.client', new Alias($config['http']['client'], false));
        $container->setAlias('nexy_slack.http.request_factory', new Alias($config['http']['request_factory'], false));
        $container->setAlias('nexy_slack.http.stream_factory', new Alias($config['http']['stream_factory'], false));

        // Unset the not needed keys for the Slack config.
        unset($config['http'], $config['endpoint']);
        $container->setParameter('nexy_slack.config', $config);

        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('client.xml');
    }
}