<commit_before><?php

/**
 * Created by PhpStorm.
 * User: Erwan
 * Date: 02/04/2015
 * Time: 11:41.
 */
namespace Conjecto\Nemrod\Bundle\ElasticaBundle\DependencyInjection\CompilerPass;

use Conjecto\Nemrod\ElasticSearch\JsonLdFrameLoader;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;

class ElasticaFramingRegistrationPass implements CompilerPassInterface
{
    /**
     * @param ContainerBuilder $container
     *
     * @throws \InvalidArgumentException
     */
    public function process(ContainerBuilder $container)
    {
        $config = $container->getExtensionConfig('elastica')[0];
        $jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
        $confManager = $container->getDefinition('nemrod.elastica.config_manager');
        $filiationBuilder = $container->get('nemrod.filiation.builder');
        $jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);

        foreach ($config['indexes'] as $name => $index) {
            $indexName = isset($index['index_name']) ? $index['index_name']: $name;
            foreach ($index['types'] as $typeName => $settings) {
                $jsonLdFrameLoader->setEsIndex($name);
                $frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
                $settings['frame'] = $frame;
                if (isset($frame['@type']) || isset($settings['type'])) {
                    $type = '';
                    if (isset($settings['type'])) {
                        $type = $settings['type'];
                    } elseif (isset($frame['@type'])) {
                        $type = $frame['@type'];
                    }

                    //type
                    $typeId = 'nemrod.elastica.type.'.$name.'.'.$typeName;
                    $indexId = 'nemrod.elastica.index.'.$name;
                    $typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
                    $typeDef->replaceArgument(0, $typeName);
                    $typeDef->setFactory(array(new Reference($indexId), 'getType'));
                    $typeDef->addTag('nemrod.elastica.type', array('type' => $type));

                    $container->setDefinition($typeId, $typeDef);

                    //registering config to configManager
                    $settings['type_service_id'] = $typeId;
                    $confManager->addMethodCall('setConfig', array($type, $settings));
                }
            }
        }
    }
}<commit_msg>fix ElasticaFramingRegistrationPass<commit_after><?php

/**
 * Created by PhpStorm.
 * User: Erwan
 * Date: 02/04/2015
 * Time: 11:41.
 */
namespace Conjecto\Nemrod\Bundle\ElasticaBundle\DependencyInjection\CompilerPass;

use Conjecto\Nemrod\ElasticSearch\JsonLdFrameLoader;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;

class ElasticaFramingRegistrationPass implements CompilerPassInterface
{
    /**
     * @param ContainerBuilder $container
     *
     * @throws \InvalidArgumentException
     */
    public function process(ContainerBuilder $container)
    {
        $config = $container->getExtensionConfig('elastica')[0];
        $jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
        $confManager = $container->getDefinition('nemrod.elastica.config_manager');
        $filiationBuilder = $container->get('nemrod.filiation.builder');
        $jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);

        foreach ($config['indexes'] as $name => $index) {
            $indexName = isset($index['index_name']) ? $index['index_name']: $name;
            foreach ($index['types'] as $typeName => $settings) {
                $jsonLdFrameLoader->setEsIndex($name);
                $frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
                $settings['frame'] = $frame;
                if (isset($frame['@type']) || isset($settings['type'])) {
                    $type = '';
                    if (isset($settings['type'])) {
                        $type = $settings['type'];
                    } elseif (isset($frame['@type'])) {
                        $type = $frame['@type'];
                    }

                    //type
                    $typeId = 'nemrod.elastica.type.'.$name.'.'.$typeName;
                    $indexId = 'nemrod.elastica.index.'.$name;
                    $typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
                    $typeDef->replaceArgument(0, $type);
                    $typeDef->setFactory(array(new Reference($indexId), 'getType'));
                    $typeDef->addTag('nemrod.elastica.type', array('type' => $type));

                    $container->setDefinition($typeId, $typeDef);

                    //registering config to configManager
                    $settings['type_service_id'] = $typeId;
                    $confManager->addMethodCall('setConfig', array($type, $settings));
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.14089219330855018, 'fraction_numerical': 0.0052044609665427505, 'mean_word_length': 2.4056962025316455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1470334', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1422, 'n_words': 213}