Skip to content

Commit

Permalink
Preload Autoloader class when the ORM is used
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyweb committed May 15, 2020
1 parent 3a9f78c commit 6e4614d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion DependencyInjection/DoctrineExtension.php
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\ORM\UnitOfWork;
use LogicException;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
Expand Down Expand Up @@ -349,7 +350,7 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->setParameter('doctrine.orm.' . $key, $config[$key]);
}

$container->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
$container->setAlias('doctrine.orm.entity_manager', $defaultEntityManagerDefinitionId = sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
$container->getAlias('doctrine.orm.entity_manager')->setPublic(true);

$config['entity_managers'] = $this->fixManagersAutoMappings($config['entity_managers'], $container->getParameter('kernel.bundles'));
Expand Down Expand Up @@ -380,6 +381,14 @@ protected function ormLoad(array $config, ContainerBuilder $container)

$container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class)
->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG);

/**
* @see DoctrineBundle::boot()
*/
$container->getDefinition($defaultEntityManagerDefinitionId)
->addTag('container.preload', [
'class' => Autoloader::class,
]);
}

/**
Expand Down

0 comments on commit 6e4614d

Please sign in to comment.