Skip to content

Commit

Permalink
Merge pull request #502 from dunglas/property_info
Browse files Browse the repository at this point in the history
Register the PropertyInfo extractor from the Symfony Bridge
  • Loading branch information
mikeSimonson committed Apr 21, 2016
2 parents 56db77e + fee8d3b commit fd51907
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
30 changes: 30 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,16 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$def->setFactoryMethod('create');
}

$loadPropertyInfoExtractor = interface_exists('Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface')
&& class_exists('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor');

foreach ($config['entity_managers'] as $name => $entityManager) {
$entityManager['name'] = $name;
$this->loadOrmEntityManager($entityManager, $container);

if ($loadPropertyInfoExtractor) {
$this->loadPropertyInfoExtractor($name, $container);
}
}

if ($config['resolve_target_entities']) {
Expand Down Expand Up @@ -758,6 +765,29 @@ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $c
$this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container);
}

/**
* Loads a property info extractor for each defined entity manager.
*
* @param string $entityManagerName
* @param ContainerBuilder $container
*/
private function loadPropertyInfoExtractor($entityManagerName, ContainerBuilder $container)
{
$metadataFactoryService = sprintf('doctrine.orm.%s_entity_manager.metadata_factory', $entityManagerName);

$metadataFactoryDefinition = $container->register($metadataFactoryService, 'Doctrine\Common\Persistence\Mapping\ClassMetadataFactory');
$metadataFactoryDefinition->setFactory(array(
new Reference(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName)),
'getMetadataFactory'
));
$metadataFactoryDefinition->setPublic(false);

$propertyExtractorDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.property_info_extractor', $entityManagerName), 'Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor');
$propertyExtractorDefinition->addArgument(new Reference($metadataFactoryService));
$propertyExtractorDefinition->addTag('property_info.list_extractor', array('priority' => -1001));
$propertyExtractorDefinition->addTag('property_info.type_extractor', array('priority' => -999));
}

/**
* @param array $objectManager
* @param ContainerBuilder $container
Expand Down
8 changes: 8 additions & 0 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,13 @@ public function testContainer()
} else {
$this->assertFalse($container->has('doctrine.dbal.default_connection.events.mysqlsessioninit'));
}

if (interface_exists('Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface') && class_exists('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor')) {
$this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadataFactory', $container->get('doctrine.orm.default_entity_manager.metadata_factory'));
$this->assertInstanceOf('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor', $container->get('doctrine.orm.default_entity_manager.property_info_extractor'));
} else {
$this->assertFalse($container->has('doctrine.orm.default_entity_manager.metadata_factory'));
$this->assertFalse($container->has('doctrine.orm.default_entity_manager.property_info_extractor'));
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
"doctrine/orm": "~2.3",
"symfony/yaml": "~2.2|~3.0",
"symfony/validator": "~2.2|~3.0",
"symfony/property-info": "~2.8|~3.0",
"symfony/phpunit-bridge": "~2.7|~3.0",
"twig/twig": "~1.10",
"satooshi/php-coveralls": "~0.6.1",
"phpunit/phpunit": "~4"
},
"suggest": {
"symfony/web-profiler-bundle": "to use the data collector",
"symfony/web-profiler-bundle": "To use the data collector.",
"doctrine/orm": "The Doctrine ORM integration is optional in the bundle."
},
"autoload": {
Expand Down

0 comments on commit fd51907

Please sign in to comment.