<commit_before><?php

namespace Knp\RadBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Knp\RadBundle\Finder\ClassFinder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\DependencyInjection\Container;
use Knp\RadBundle\DependencyInjection\Definition\DoctrineRepositoryFactory;
use Knp\RadBundle\DependencyInjection\ServiceIdGenerator;

class RegisterDoctrineRepositoriesPass implements CompilerPassInterface
{
    private $bundle;
    private $definitionFactory;
    private $serviceIdGenerator;

    public function __construct(BundleInterface $bundle, DoctrineRepositoryFactory $definitionFactory = null, ServiceIdGenerator $serviceIdGenerator = null)
    {
        $this->bundle             = $bundle;
        $this->definitionFactory  = $definitionFactory ?: new DoctrineRepositoryFactory();
        $this->serviceIdGenerator = $serviceIdGenerator ?: new ServiceIdGenerator();
    }

    /**
     * {@inheritDoc}
     */
    public function process(ContainerBuilder $container)
    {
        $namespace = $this->bundle->getNamespace().'\Entity';

        $classes = $container->get('doctrine.orm.entity_manager')->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
        
        foreach ($classes as $class) {
            if (strpos($class, $this->bundle->getNamespace()) === 0) {
                $id = $this->serviceIdGenerator->generateForBundleClass($this->bundle, $class, 'repository');

                if ($container->hasDefinition($id)) {
                    continue;
                }

                $def = $this->definitionFactory->createDefinition($class);

                $container->setDefinition($id, $def);
            }
        }
    }
}
<commit_msg>Create definition only if doctrine.orm.entity_manager was Defined<commit_after><?php

namespace Knp\RadBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Knp\RadBundle\Finder\ClassFinder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\DependencyInjection\Container;
use Knp\RadBundle\DependencyInjection\Definition\DoctrineRepositoryFactory;
use Knp\RadBundle\DependencyInjection\ServiceIdGenerator;

class RegisterDoctrineRepositoriesPass implements CompilerPassInterface
{
    private $bundle;
    private $definitionFactory;
    private $serviceIdGenerator;

    public function __construct(BundleInterface $bundle, DoctrineRepositoryFactory $definitionFactory = null, ServiceIdGenerator $serviceIdGenerator = null)
    {
        $this->bundle             = $bundle;
        $this->definitionFactory  = $definitionFactory ?: new DoctrineRepositoryFactory();
        $this->serviceIdGenerator = $serviceIdGenerator ?: new ServiceIdGenerator();
    }

    /**
     * {@inheritDoc}
     */
    public function process(ContainerBuilder $container)
    {
        $namespace = $this->bundle->getNamespace().'\Entity';

        if ($container->has('doctrine.orm.entity_manager')) {
            $classes = $container->get('doctrine.orm.entity_manager')->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
            
            foreach ($classes as $class) {
                if (strpos($class, $this->bundle->getNamespace()) === 0) {
                    $id = $this->serviceIdGenerator->generateForBundleClass($this->bundle, $class, 'repository');

                    if ($container->hasDefinition($id)) {
                        continue;
                    }

                    $def = $this->definitionFactory->createDefinition($class);

                    $container->setDefinition($id, $def);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.1124612202688728, 'fraction_numerical': 0.000517063081695967, 'mean_word_length': 3.261013215859031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '6202276', 'n_tokens_mistral': 971, 'n_tokens_neox': 948, 'n_words': 158}