Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload Autoloader class when the ORM is used #1167

Merged
merged 1 commit into from May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new logic above uncovered this error in the configuration. Looks like we don't check whether the default entity manager even exists 🤷‍♂️

proxy_namespace: Proxies
auto_generate_proxy_classes: true
entity_managers:
Expand Down