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

Wire up type aliases support in EntityValueResolver #1790

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,19 +541,22 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$controllerResolverDefaults['evict_cache'] = true;
}

if ($controllerResolverDefaults) {
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class))->setArguments([
null,
null,
null,
$controllerResolverDefaults['mapping'] ?? null,
null,
null,
null,
$controllerResolverDefaults['evict_cache'] ?? null,
$controllerResolverDefaults['disabled'] ?? false,
]));
}
$valueResolverDefinition = $container->getDefinition('doctrine.orm.entity_value_resolver');

$valueResolverDefinition->setArgument(2, (new Definition(MapEntity::class))->setArguments([
null,
null,
null,
$controllerResolverDefaults['mapping'] ?? null,
null,
null,
null,
$controllerResolverDefaults['evict_cache'] ?? null,
$controllerResolverDefaults['disabled'] ?? false,
]));

// Symfony 7.2 and higher expose type alias support in the EntityValueResolver
$valueResolverDefinition->setArgument(3, $config['resolve_target_entities']);
}

// not available in Doctrine ORM 3.0 and higher
Expand Down
6 changes: 6 additions & 0 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
use Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
Expand All @@ -23,6 +24,7 @@
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;

use function class_exists;
use function interface_exists;

class ContainerTest extends TestCase
Expand All @@ -39,6 +41,10 @@ public function testContainer(): void
$this->assertInstanceOf(Reader::class, $container->get('doctrine.orm.metadata.annotation_reader'));
}

if (class_exists(EntityValueResolver::class)) {
$this->assertInstanceOf(EntityValueResolver::class, $container->get('doctrine.orm.entity_value_resolver'));
}

$this->assertInstanceOf(DoctrineDataCollector::class, $container->get('data_collector.doctrine'));
$this->assertInstanceOf(DBALConfiguration::class, $container->get('doctrine.dbal.default_connection.configuration'));
$this->assertInstanceOf(EventManager::class, $container->get('doctrine.dbal.default_connection.event_manager'));
Expand Down
20 changes: 18 additions & 2 deletions tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,13 +1497,29 @@ public function testControllerResolver(bool $simpleEntityManagerConfig): void
$config['orm'] = [];
}

$config['orm']['controller_resolver'] = ['auto_mapping' => true];
$config['orm']['controller_resolver'] = ['auto_mapping' => true];
$config['orm']['resolve_target_entities'] = ['Throwable' => 'stdClass'];

$extension->load([$config], $container);

$controllerResolver = $container->getDefinition('doctrine.orm.entity_value_resolver');

$this->assertEquals([new Reference('doctrine'), new Reference('doctrine.orm.entity_value_resolver.expression_language', $container::IGNORE_ON_INVALID_REFERENCE)], $controllerResolver->getArguments());
$this->assertEquals([
0 => new Reference('doctrine'),
1 => new Reference('doctrine.orm.entity_value_resolver.expression_language', $container::IGNORE_ON_INVALID_REFERENCE),
2 => (new Definition(MapEntity::class))->setArguments([
null,
null,
null,
null,
null,
null,
null,
null,
false,
]),
3 => ['Throwable' => 'stdClass'],
], $controllerResolver->getArguments());

$container = $this->getContainer();

Expand Down
Loading