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 authored and alcaeus committed May 25, 2020
1 parent a366dc6 commit b4c55dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion DependencyInjection/DoctrineExtension.php
Expand Up @@ -6,6 +6,7 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
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 @@ -363,7 +364,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 @@ -397,6 +398,14 @@ protected function ormLoad(array $config, ContainerBuilder $container)

$container->registerForAutoconfiguration(EventSubscriberInterface::class)
->addTag('doctrine.event_subscriber');

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

/**
Expand Down
Expand Up @@ -10,7 +10,7 @@ doctrine:
memory: true

orm:
default_entity_manager: dm2
default_entity_manager: default
proxy_namespace: Proxies
auto_generate_proxy_classes: true
entity_managers:
Expand Down

0 comments on commit b4c55dd

Please sign in to comment.