<commit_before><?php

namespace Liip\CacheControlBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor,
    Symfony\Component\Config\FileLocator,
    Symfony\Component\HttpKernel\DependencyInjection\Extension,
    Symfony\Component\DependencyInjection\Loader\XmlFileLoader,
    Symfony\Component\DependencyInjection\ContainerBuilder,
    Symfony\Component\DependencyInjection\Reference,
    Symfony\Component\DependencyInjection\DefinitionDecorator;

class LiipCacheControlExtension extends Extension
{
    /**
     * Loads the services based on your application configuration.
     *
     * @param array $configs
     * @param ContainerBuilder $container
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $config = $processor->processConfiguration($configuration, $configs);

        if (empty($config['rules']) && $config['purger']) {
            return;
        }

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

        if (isset($config['rules'])) {
            foreach ($config['rules'] as $cache) {
                $matcher = $this->createRequestMatcher(
                    $container,
                    $cache['path']
                );

                $container->getDefinition($this->getAlias().'.response_listener')
                          ->addMethodCall('add', array($matcher, $cache['controls']));
            }
        }

        if (isset($config['purger'])) {
            $container->setParameter($this->getAlias().'.varnishes', $config['purger']['varnishes']);
            $container->setParameter($this->getAlias().'.domain', $config['purger']['domain']);
            $container->setParameter($this->getAlias().'.port', $config['purger']['port']);
        }
    }

    protected function createRequestMatcher(ContainerBuilder $container, $path = null)<commit_msg>lets not bother with optimizing the service container<commit_after><?php

namespace Liip\CacheControlBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor,
    Symfony\Component\Config\FileLocator,
    Symfony\Component\HttpKernel\DependencyInjection\Extension,
    Symfony\Component\DependencyInjection\Loader\XmlFileLoader,
    Symfony\Component\DependencyInjection\ContainerBuilder,
    Symfony\Component\DependencyInjection\Reference,
    Symfony\Component\DependencyInjection\DefinitionDecorator;

class LiipCacheControlExtension extends Extension
{
    /**
     * Loads the services based on your application configuration.
     *
     * @param array $configs
     * @param ContainerBuilder $container
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $config = $processor->processConfiguration($configuration, $configs);

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

        if (isset($config['rules'])) {
            foreach ($config['rules'] as $cache) {
                $matcher = $this->createRequestMatcher(
                    $container,
                    $cache['path']
                );

                $container->getDefinition($this->getAlias().'.response_listener')
                          ->addMethodCall('add', array($matcher, $cache['controls']));
            }
        }

        if (isset($config['purger'])) {
            $container->setParameter($this->getAlias().'.varnishes', $config['purger']['varnishes']);
            $container->setParameter($this->getAlias().'.domain', $config['purger']['domain']);
            $container->setParameter($this->getAlias().'.port', $config['purger']['port']);
        }
    }

    protected function createRequestMatcher(ContainerBuilder $container, $path = null)
{'fraction_non_alphanumeric': 0.137596417019159, 'fraction_numerical': 0.0, 'mean_word_length': 3.0119760479041915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6713172', 'n_tokens_mistral': 1017, 'n_tokens_neox': 989, 'n_words': 166}