Skip to content

Commit

Permalink
Add option "doctrine.orm.enable_lazy_ghost_objects"
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 8, 2022
1 parent 84d23e5 commit a19dc41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private function addOrmSection(ArrayNodeDefinition $node): void
$excludedKeys = [
'default_entity_manager' => true,
'auto_generate_proxy_classes' => true,
'enable_lazy_ghost_objects' => true,
'proxy_dir' => true,
'proxy_namespace' => true,
'resolve_target_entities' => true,
Expand Down Expand Up @@ -431,6 +432,8 @@ private function addOrmSection(ArrayNodeDefinition $node): void
})
->end()
->end()
->booleanNode('enable_lazy_ghost_objects')->defaultFalse()
->end()
->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end()
->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
->arrayNode('controller_resolver')
Expand Down
15 changes: 14 additions & 1 deletion DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
use Doctrine\ORM\Configuration as OrmConfiguration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Id\AbstractIdGenerator;
Expand Down Expand Up @@ -489,8 +490,15 @@ protected function ormLoad(array $config, ContainerBuilder $container)

$container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']);

$options = ['auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace'];
$options = ['auto_generate_proxy_classes', 'enable_lazy_ghost_objects', 'proxy_dir', 'proxy_namespace'];
foreach ($options as $key) {
if ($key === 'enable_lazy_ghost_objects' && $config[$key] && ! method_exists(OrmConfiguration::class, 'setLazyGhostObjectEnabled')) {
throw new LogicException(
'Lazy ghost objects cannot be enabled because the "doctrine/orm" library'
. ' version 2.14 or higher is not installed. Please run "composer update doctrine/orm".'
);
}

$container->setParameter('doctrine.orm.' . $key, $config[$key]);
}

Expand Down Expand Up @@ -593,6 +601,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
'setProxyDir' => '%doctrine.orm.proxy_dir%',
'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
'setLazyGhostObjectEnabled' => '%doctrine.orm.enable_lazy_ghost_objects%',
'setSchemaIgnoreClasses' => $entityManager['schema_ignore_classes'],
'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
Expand All @@ -601,6 +610,10 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
'setEntityListenerResolver' => new Reference(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name'])),
];

if (! method_exists(OrmConfiguration::class, 'setLazyGhostObjectEnabled')) {
unset($methods['setLazyGhostObjectEnabled']);
}

$listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $entityManager['name']);
$listenerDef = $container->setDefinition($listenerId, new Definition('%doctrine.orm.listeners.attach_entity_listeners.class%'));
$listenerTagParams = ['event' => 'loadClassMetadata'];
Expand Down

0 comments on commit a19dc41

Please sign in to comment.