<commit_before><?php

namespace Gos\Bundle\PubSubRouterBundle\DependencyInjection\CompilerPass;

use Gos\Bundle\PubSubRouterBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class RouterCompilerPass implements CompilerPassInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        $processor = new Processor();
        $configs = $processor->processConfiguration(new Configuration(), $container->getExtensionConfig('gos_pubsub_router'));

        $configs['loaders'][] = '@gos_pubsub_router.yaml.loader';
        $container->setParameter('gos_pubsub_registered_routers', array_keys($configs['routers']));

        $debugCmdDef = $container->getDefinition('gos_pubsub_router.debug.command');

        foreach ($configs['routers'] as $name => $routerConf) {

            //RouteCollection
            $collectionServiceName = 'gos_pubsub_router.collection.' . $name;
            $collectionDef = new Definition('Gos\Bundle\PubSubRouterBundle\Router\RouteCollection');
            $container->setDefinition($collectionServiceName, $collectionDef);

            //Matcher
            $matcherDef = $container->getDefinition('gos_pubsub_router.matcher');
            $matcherDef
                ->setClass($configs['matcher_class'])
                ->addMethodCall('setCollection', [new Reference($collectionServiceName)]);

            //Generator
            $generatorDef = $container->getDefinition('gos_pubsub_router.generator');
            $generatorDef
                ->setClass($configs['generator_class'])
                ->addMethodCall('setCollection', [new Reference($collectionServiceName)]);

            //RouterLoader
            $routeLoaderServiceName = 'gos_pubsub_router.loader.' . $name;
            $routeLoaderDef = new Definition($configs['route_loader_class']);
            /**
            * Make it public for symfony 4
            * @author <NAME> <<EMAIL>>
            */
            $routeLoaderDef->setPublic(true);

            $routeLoaderDef->setArguments([
                new Reference($collectionServiceName),
                new Reference('gos_pubsub_router.php_file.cache'),
                $name,
            ]);

            foreach ($routerConf['resources'] as $resource) {
                $routeLoaderDef->addMethodCall('addResource', array($resource));
            }

            foreach ($configs['loaders'] as $loaderRef) {
                $routeLoaderDef->addMethodCall('addLoader', [new Reference(ltrim($loaderRef, '@'))]);
            }

            $container->setDefinition($routeLoaderServiceName, $routeLoaderDef);

            //Router
            $routerServiceName = 'gos_pubsub_router.' . $name;

            $routerDef = new Definition($configs['router_class'], [
                new Reference($collectionServiceName),
                new Reference('gos_pubsub_router.matcher'),
                new Reference('gos_pubsub_router.generator'),
                new Reference($routeLoaderServiceName),
                $name,
            ]);

            $container->setDefinition($routerServiceName, $routerDef);

            $debugCmdDef->addMethodCall('addRouter', [new Reference($routerServiceName)]);
        }
    }
}<commit_msg>Routers aren't injected into the command anymore<commit_after><?php

namespace Gos\Bundle\PubSubRouterBundle\DependencyInjection\CompilerPass;

use Gos\Bundle\PubSubRouterBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class RouterCompilerPass implements CompilerPassInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        $processor = new Processor();
        $configs = $processor->processConfiguration(new Configuration(), $container->getExtensionConfig('gos_pubsub_router'));

        $configs['loaders'][] = '@gos_pubsub_router.yaml.loader';
        $container->setParameter('gos_pubsub_registered_routers', array_keys($configs['routers']));

        foreach ($configs['routers'] as $name => $routerConf) {

            //RouteCollection
            $collectionServiceName = 'gos_pubsub_router.collection.' . $name;
            $collectionDef = new Definition('Gos\Bundle\PubSubRouterBundle\Router\RouteCollection');
            $container->setDefinition($collectionServiceName, $collectionDef);

            //Matcher
            $matcherDef = $container->getDefinition('gos_pubsub_router.matcher');
            $matcherDef
                ->setClass($configs['matcher_class'])
                ->addMethodCall('setCollection', [new Reference($collectionServiceName)]);

            //Generator
            $generatorDef = $container->getDefinition('gos_pubsub_router.generator');
            $generatorDef
                ->setClass($configs['generator_class'])
                ->addMethodCall('setCollection', [new Reference($collectionServiceName)]);

            //RouterLoader
            $routeLoaderServiceName = 'gos_pubsub_router.loader.' . $name;
            $routeLoaderDef = new Definition($configs['route_loader_class']);
            /**
            * Make it public for symfony 4
            * @author <NAME> <<EMAIL>>
            */
            $routeLoaderDef->setPublic(true);

            $routeLoaderDef->setArguments([
                new Reference($collectionServiceName),
                new Reference('gos_pubsub_router.php_file.cache'),
                $name,
            ]);

            foreach ($routerConf['resources'] as $resource) {
                $routeLoaderDef->addMethodCall('addResource', array($resource));
            }

            foreach ($configs['loaders'] as $loaderRef) {
                $routeLoaderDef->addMethodCall('addLoader', [new Reference(ltrim($loaderRef, '@'))]);
            }

            $container->setDefinition($routeLoaderServiceName, $routeLoaderDef);

            //Router
            $routerServiceName = 'gos_pubsub_router.' . $name;

            $routerDef = new Definition($configs['router_class'], [
                new Reference($collectionServiceName),
                new Reference('gos_pubsub_router.matcher'),
                new Reference('gos_pubsub_router.generator'),
                new Reference($routeLoaderServiceName),
                $name,
            ]);

            $container->setDefinition($routerServiceName, $routerDef);
        }
    }
}
{'fraction_non_alphanumeric': 0.1193058568329718, 'fraction_numerical': 0.00028922631959508316, 'mean_word_length': 2.740400216333153, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 45, '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': '7245677', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1677, 'n_words': 253}