<commit_before><?php

namespace Knp\Bundle\LastTweetsBundle\DependencyInjection;

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

/**
 * 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 KnpLastTweetsExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

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

        // Try to load Buzz service if not found
        if (!$container->hasDefinition('buzz')) {
            $loader->load('buzz.yml');
        }

        // Load the good fetcher driver
        $fetcherConfig = isset($config['fetcher']) ? $config['fetcher'] : array();

        $driver = 'api';

        if (isset($fetcherConfig['driver'])) {
            $driver = strtolower($fetcherConfig['driver']);
        }

        if (!in_array($driver, array('oauth', 'api', 'zend_cache', 'array'))) {
            throw new \InvalidArgumentException('Invalid knp_last_tweets driver specified');
        }

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/fetcher_driver'));

        if ($container->hasDefinition('inori_twitter_app')) {
            $loader->load('oauth.yml');
        } elseif($driver == 'oauth') {
            throw new \InvalidArgumentException('You should install InoriTwitterBundle');
        }

        $loader->load($driver . '.yml');

        if ('zend_cache' === $driver) {
            $driverOptions = array();
            if (isset($fetcherConfig['options'])) {
                $driverOptions = $fetcherConfig['options'];

                if (isset($driverOptions['method'])) {

                    if (!$container->hasDefinition('inori_twitter_app') && $driverOptions['method'] == 'oauth') {
                        throw new \InvalidArgumentException('You should install InoriTwitterBundle');
                    }
                    if (!in_array($driverOptions['method'], array('oauth', 'api'))) {
                        throw new \InvalidArgumentException('Invalid knp_last_tweets secondary driver specified');
                    }

                    $container->setAlias('knp_last_tweets.last_tweets_additional_fetcher', 'knp_last_tweets.last_tweets_fetcher.' . $driverOptions['method']);
                } else {
                    $container->setAlias('knp_last_tweets.last_tweets_additional_fetcher', 'knp_last_tweets.last_tweets_fetcher.api');
                }
            }
            if (!empty($driverOptions['cache_name'])) {
                $container->setParameter('knp_last_tweets.last_tweets_fetcher.zend_cache.cache_name', $driverOptions['cache_name']);
            }
        }

        $container->setAlias('knp_last_tweets.last_tweets_fetcher', 'knp_last_tweets.last_tweets_fetcher.' . $driver);
    }
}<commit_msg>Fix extension<commit_after><?php

namespace Knp\Bundle\LastTweetsBundle\DependencyInjection;

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

/**
 * 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 KnpLastTweetsExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

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

        // Try to load Buzz service if not found
        if (!$container->hasDefinition('buzz')) {
            $loader->load('buzz.yml');
        }

        // Load the good fetcher driver
        $fetcherConfig = isset($config['fetcher']) ? $config['fetcher'] : array();

        $driver = 'api';

        if (isset($fetcherConfig['driver'])) {
            $driver = strtolower($fetcherConfig['driver']);
        }

        if (!in_array($driver, array('oauth', 'api', 'zend_cache', 'array'))) {
            throw new \InvalidArgumentException('Invalid knp_last_tweets driver specified');
        }

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/fetcher_driver'));

        if (class_exists('Inori\TwitterAppBundle\Services\TwitterApp')) {
            $loader->load('oauth.yml');
        } elseif($driver == 'oauth') {
            throw new \InvalidArgumentException('You should install InoriTwitterBundle');
        }

        $loader->load($driver . '.yml');

        if ('zend_cache' === $driver) {
            $driverOptions = array();
            if (isset($fetcherConfig['options'])) {
                $driverOptions = $fetcherConfig['options'];

                if (isset($driverOptions['method'])) {

                    if (!class_exists('Inori\TwitterAppBundle\Services\TwitterApp') && $driverOptions['method'] == 'oauth') {
                        throw new \InvalidArgumentException('You should install InoriTwitterBundle');
                    }
                    if (!in_array($driverOptions['method'], array('oauth', 'api'))) {
                        throw new \InvalidArgumentException('Invalid knp_last_tweets secondary driver specified');
                    }

                    $container->setAlias('knp_last_tweets.last_tweets_additional_fetcher', 'knp_last_tweets.last_tweets_fetcher.' . $driverOptions['method']);
                } else {
                    $container->setAlias('knp_last_tweets.last_tweets_additional_fetcher', 'knp_last_tweets.last_tweets_fetcher.api');
                }
            }
            if (!empty($driverOptions['cache_name'])) {
                $container->setParameter('knp_last_tweets.last_tweets_fetcher.zend_cache.cache_name', $driverOptions['cache_name']);
            }
        }

        $container->setAlias('knp_last_tweets.last_tweets_fetcher', 'knp_last_tweets.last_tweets_fetcher.' . $driver);
    }
}
{'fraction_non_alphanumeric': 0.13544152744630072, 'fraction_numerical': 0.0, 'mean_word_length': 2.720865704772475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5099046', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1831, 'n_words': 313}