<commit_before><?php
/*
 * This file is part of the Artscore Studio Framework package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ASF\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Compiler Pass for Entity Managers tagged services
 *  
 * @author <NAME> <<EMAIL>>
 *
 */
class ASFEntityManagerPass implements CompilerPassInterface
{
    /**
     * {@inheritDoc}
     * @see \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::process()
     */
    public function process(ContainerBuilder $container)
    {
        $tagged_services = $container->findTaggedServiceIds('asf_core.manager');
		
        foreach($tagged_services as $id => $tags) {
            foreach($tags as $attributes) {
                
                if ( !isset($attributes['entity']) ) {
                    throw new \LogicException(sprintf("Attribute \"entity\" missing for service tagged \"asf_core.manager\" for service id \"%s\"", $id));
                }
                
                $class = false !== strpos($container->getDefinition($id)->getClass(), '%') ? $container->getParameter($this->translateParameter($container->getDefinition($id)->getClass())) : $container->getDefinition($id)->getClass();
                $entity = false !== strpos($attributes['entity'], '%') ? $container->getParameter($this->translateParameter($attributes['entity'])) : $attributes['entity'];
                
                if ( !class_exists($class) ) {
                	$container->getDefinition($id)->setClass('ASF\CoreBundle\Entity\Manager\ASFEntityManager');
                }
                
                $container->getDefinition($id)->addArgument(new Reference('doctrine.orm.entity_manager'));
                $container->getDefinition($id)->addArgument($entity);
            }
        }
    }
    
    /**
     * Change parameter like %parameter_name% to parameter_name for get it with $container->getParamter('parameter_name')
     * 
     * @param strinng $parameter
     */
    private function translateParameter($parameter)
    {
        return trim($parameter, '%');
    }
}<commit_msg>Do array_merge with arguments passed in services and arguments injected by compiler pass in correct order<commit_after><?php
/*
 * This file is part of the Artscore Studio Framework package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ASF\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Compiler Pass for Entity Managers tagged services
 *  
 * @author <NAME> <<EMAIL>>
 *
 */
class ASFEntityManagerPass implements CompilerPassInterface
{
    /**
     * {@inheritDoc}
     * @see \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::process()
     */
    public function process(ContainerBuilder $container)
    {
        $tagged_services = $container->findTaggedServiceIds('asf_core.manager');
		
        foreach($tagged_services as $id => $tags) {
            foreach($tags as $attributes) {
                
                if ( !isset($attributes['entity']) ) {
                    throw new \LogicException(sprintf("Attribute \"entity\" missing for service tagged \"asf_core.manager\" for service id \"%s\"", $id));
                }
                
                $class = false !== strpos($container->getDefinition($id)->getClass(), '%') ? $container->getParameter($this->translateParameter($container->getDefinition($id)->getClass())) : $container->getDefinition($id)->getClass();
                $entity = false !== strpos($attributes['entity'], '%') ? $container->getParameter($this->translateParameter($attributes['entity'])) : $attributes['entity'];
                
                if ( !class_exists($class) ) {
                	$container->getDefinition($id)->setClass('ASF\CoreBundle\Entity\Manager\ASFEntityManager');
                }
                
                $arguments = $container->getDefinition($id)->getArguments();
                $injected_args = array(
                    new Reference('doctrine.orm.entity_manager'),
                    $entity
                );
                
                $container->getDefinition($id)->setArguments(array_merge($injected_args, $arguments));
            }
        }
    }
    
    /**
     * Change parameter like %parameter_name% to parameter_name for get it with $container->getParamter('parameter_name')
     * 
     * @param strinng $parameter
     */
    private function translateParameter($parameter)
    {
        return trim($parameter, '%');
    }
}
{'fraction_non_alphanumeric': 0.1312733713835859, 'fraction_numerical': 0.0, 'mean_word_length': 2.7700296735905043, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, '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': '822101', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1252, 'n_words': 265}