<commit_before><?php

namespace Assimtech\DislogBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerInterface;

class AssimtechDislogExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');

        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $this
            ->createHandlerDefinition($config, $container)
            ->createLoggerDefinition($config, $container)
        ;
    }

    protected function createHandlerDefinition($config, ContainerBuilder $container)
    {
        $handlerServiceId = 'assimtech_dislog.handler';

        $handlers = array_keys($config['handler']);
        $handlerType = $handlers[0];
        $handlerConfig = $config['handler'][$handlerType];

        $definition = null;
        switch ($handlerType) {
            case 'stream':
                $arguments = array(
                    $handlerConfig['resource'],
                    new Reference($handlerConfig['identity_generator']),
                    new Reference($handlerConfig['serializer']),
                );
                $definition = new Definition('Assimtech\Dislog\Handler\Stream', $arguments);
                break;
            case 'doctrine_object_manager':
                $arguments = array(
                    new Reference($handlerConfig['object_manager']),
                );
                $definition = new Definition('Assimtech\Dislog\Handler\DoctrineObjectManager', $arguments);
                break;
            case 'service':
                $container->setAlias(
                    $handlerServiceId,
                    $handlerConfig['name']
                );
                return $this;
        }

        $container->setDefinition($handlerServiceId, $definition);

        return $this;
    }

    protected function createLoggerDefinition($config, ContainerBuilder $container)
    {
        $arguments = array(
            new Reference('assimtech_dislog.api_call.factory'),
            new Reference('assimtech_dislog.handler'),
            $config['preferences'],
            new Reference($config['psr_logger'], ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
        );

        $definition = new Definition('Assimtech\Dislog\ApiCallLogger', $arguments);

        $container->setDefinition('assimtech_dislog.logger', $definition);

        return $this;
    }<commit_msg>Added unsupported handler exception back<commit_after><?php

namespace Assimtech\DislogBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerInterface;
use InvalidArgumentException;

class AssimtechDislogExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');

        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $this
            ->createHandlerDefinition($config, $container)
            ->createLoggerDefinition($config, $container)
        ;
    }

    protected function createHandlerDefinition($config, ContainerBuilder $container)
    {
        $handlerServiceId = 'assimtech_dislog.handler';

        $handlers = array_keys($config['handler']);
        $handlerType = $handlers[0];
        $handlerConfig = $config['handler'][$handlerType];

        switch ($handlerType) {
            case 'stream':
                $arguments = array(
                    $handlerConfig['resource'],
                    new Reference($handlerConfig['identity_generator']),
                    new Reference($handlerConfig['serializer']),
                );
                $definition = new Definition('Assimtech\Dislog\Handler\Stream', $arguments);
                break;
            case 'doctrine_object_manager':
                $arguments = array(
                    new Reference($handlerConfig['object_manager']),
                );
                $definition = new Definition('Assimtech\Dislog\Handler\DoctrineObjectManager', $arguments);
                break;
            case 'service':
                $container->setAlias(
                    $handlerServiceId,
                    $handlerConfig['name']
                );
                return $this;
            default:
                throw new InvalidArgumentException(sprintf(
                    'Unsupported handler type: %s',
                    $handlerType
                ));
        }

        $container->setDefinition($handlerServiceId, $definition);

        return $this;
    }

    protected function createLoggerDefinition($config, ContainerBuilder $container)
    {
        $arguments = array(
            new Reference('assimtech_dislog.api_call.factory'),
            new Reference('assimtech_dislog.handler'),
            $config['preferences'],
            new Reference($config['psr_logger'], ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
        );

        $definition = new Definition('Assimtech\Dislog\ApiCallLogger', $arguments);

        $container->setDefinition('assimtech_dislog.logger', $definition);

        return $this;
    }
{'fraction_non_alphanumeric': 0.10628177792356897, 'fraction_numerical': 0.0003280301787764474, 'mean_word_length': 2.5536130536130535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '5390810', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1425, 'n_words': 253}