Skip to content

Commit

Permalink
Better feature detection for DoctrineExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 3, 2018
1 parent 82d2c63 commit 8aba9e9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions DependencyInjection/DoctrineExtension.php
Expand Up @@ -26,6 +26,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
use Symfony\Contracts\Service\ResetInterface;

/**
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
Expand Down Expand Up @@ -798,9 +799,8 @@ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $c
private function loadPropertyInfoExtractor($entityManagerName, ContainerBuilder $container)
{
$propertyExtractorDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.property_info_extractor', $entityManagerName), DoctrineExtractor::class);
if (interface_exists(PropertyInitializableExtractorInterface::class)) {
$argumentId = sprintf('doctrine.orm.%s_entity_manager', $entityManagerName);
} else {
$constructorParameterType = (new \ReflectionClass(DoctrineExtractor::class))->getConstructor()->getParameters()[0]->getType();
if (null !== $constructorParameterType && $constructorParameterType->getName() === ClassMetadataFactory::class) {
$argumentId = sprintf('doctrine.orm.%s_entity_manager.metadata_factory', $entityManagerName);

$metadataFactoryDefinition = $container->register($argumentId, ClassMetadataFactory::class);
Expand All @@ -809,6 +809,8 @@ private function loadPropertyInfoExtractor($entityManagerName, ContainerBuilder
'getMetadataFactory',
]);
$metadataFactoryDefinition->setPublic(false);
} else {
$argumentId = sprintf('doctrine.orm.%s_entity_manager', $entityManagerName);
}

$propertyExtractorDefinition->addArgument(new Reference($argumentId));
Expand Down

0 comments on commit 8aba9e9

Please sign in to comment.