<commit_before><?php

namespace Gendoria\CommandQueueBundle\DependencyInjection;

use Gendoria\CommandQueue\QueueManager\NullQueueManager;
use Gendoria\CommandQueue\QueueManager\SimpleQueueManager;
use InvalidArgumentException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class GendoriaCommandQueueExtension extends Extension
{
    /**
     * Get extension alias.
     *
     * @return string
     */
    public function getAlias()
    {
        return 'gendoria_command_queue';
    }

    /**
     * Load extension.
     *
     * @param array            $configs
     * @param ContainerBuilder $container
     * @throws InvalidArgumentException Thrown, when pool required in configuration is not present.
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration($this->getAlias());
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');

        $container->setParameter('gendoria_command_queue.pools', $config['pools']);
        if (!$config['enabled']) {
            $managerDefinition = $container->getDefinition('gendoria_command_queue.manager');
            $managerDefinition->setClass(NullQueueManager::class);
        }
        $this->setupManagers($config, $container);
    }
    
    private function setupManagers($config, ContainerBuilder $container)
    {
        //Create simple managers for each pool and tag multiple manager to receive all pools
        $managerDefinition = $container->getDefinition('gendoria_command_queue.manager');
        $poolNames = array_keys($config['pools']);
        foreach ($config['pools'] as $poolName => $poolConfig) {
            $definition = new Definition(SimpleQueueManager::class);
            $definition->addTag('gendoria_command_queue.send_manager', array('pool' => $poolName));
            $container->setDefinition('gendoria_command_queue.manager.'.$poolName, $definition);
            $managerDefinition->addTag('gendoria_command_queue.send_manager', array('pool' => $poolName, 'default' => $poolName == 'default'));
        }
        //Inject command routing to default manager
        foreach ($config['routes'] as $commandExpression => $poolName) {
            if (!in_array($poolName, $poolNames)) {
                throw new InvalidArgumentException(sprintf("Pool \"%s\" required in command routing is not present.", $poolName));
            }
            $managerDefinition->addMethodCall('addCommandRoute', array($commandExpression, $poolName));
        }
    }
}
<commit_msg>SimpleQueueManager renamed to SingleQueueManager<commit_after><?php

namespace Gendoria\CommandQueueBundle\DependencyInjection;

use Gendoria\CommandQueue\QueueManager\NullQueueManager;
use Gendoria\CommandQueue\QueueManager\SingleQueueManager;
use InvalidArgumentException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class GendoriaCommandQueueExtension extends Extension
{
    /**
     * Get extension alias.
     *
     * @return string
     */
    public function getAlias()
    {
        return 'gendoria_command_queue';
    }

    /**
     * Load extension.
     *
     * @param array            $configs
     * @param ContainerBuilder $container
     * @throws InvalidArgumentException Thrown, when pool required in configuration is not present.
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration($this->getAlias());
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');

        $container->setParameter('gendoria_command_queue.pools', $config['pools']);
        if (!$config['enabled']) {
            $managerDefinition = $container->getDefinition('gendoria_command_queue.manager');
            $managerDefinition->setClass(NullQueueManager::class);
        }
        $this->setupManagers($config, $container);
    }
    
    private function setupManagers($config, ContainerBuilder $container)
    {
        //Create simple managers for each pool and tag multiple manager to receive all pools
        $managerDefinition = $container->getDefinition('gendoria_command_queue.manager');
        $poolNames = array_keys($config['pools']);
        foreach ($config['pools'] as $poolName => $poolConfig) {
            $definition = new Definition(SingleQueueManager::class);
            $definition->addTag('gendoria_command_queue.send_manager', array('pool' => $poolName));
            $container->setDefinition('gendoria_command_queue.manager.'.$poolName, $definition);
            $managerDefinition->addTag('gendoria_command_queue.send_manager', array('pool' => $poolName, 'default' => $poolName == 'default'));
        }
        //Inject command routing to default manager
        foreach ($config['routes'] as $commandExpression => $poolName) {
            if (!in_array($poolName, $poolNames)) {
                throw new InvalidArgumentException(sprintf("Pool \"%s\" required in command routing is not present.", $poolName));
            }
            $managerDefinition->addMethodCall('addCommandRoute', array($commandExpression, $poolName));
        }
    }
}

{'fraction_non_alphanumeric': 0.11848264729620663, 'fraction_numerical': 0.0, 'mean_word_length': 3.6032689450222883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024877', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1583, 'n_words': 337}