Skip to content

Commit

Permalink
Fix dealing with Definition objects in SetDoctrineAnnotatedPrefixesPass
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 23, 2021
1 parent 4021ece commit 3fff156
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

namespace Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass;

use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class SetDoctrineAnnotatedPrefixesPass implements CompilerPassInterface
Expand All @@ -35,16 +38,35 @@ public function process(ContainerBuilder $container)
}

$managerName = $m[1];
$methodCalls = $metadataDriverImpl->getMethodCalls();

foreach ($metadataDriverImpl->getMethodCalls() as [$method, $arguments]) {
if ('addDriver' === $method) {
$isAnnotated = 'doctrine.orm.'.$managerName.'_annotation_metadata_driver' === (string) $arguments[0];
$annotatedPrefixes[$managerName][] = [
$arguments[1],
$isAnnotated ? new Reference($arguments[0]) : null,
];
foreach ($methodCalls as $i => [$method, $arguments]) {
if ('addDriver' !== $method) {
continue;
}

if ($arguments[0] instanceof Definition) {
$class = $arguments[0]->getClass();
$namespace = substr($class, 0, strrpos($class, '\\'));

if ('Doctrine\ORM\Mapping\Driver' === $namespace ? AnnotationDriver::class !== $class : !is_subclass_of($class, AbstractAnnotationDriver::class)) {
continue;
}

$id = sprintf('.%d_annotation_metadata_driver~%s', $i, ContainerBuilder::hash($arguments));
$container->setDefinition($id, $arguments[0]);
$arguments[0] = new Reference($id);
$methodCalls[$i] = $arguments;
}

$isAnnotated = false !== strpos($arguments[0], '_annotation_metadata_driver');
$annotatedPrefixes[$managerName][] = [
$arguments[1],
$isAnnotated ? new Reference($arguments[0]) : null,
];
}

$metadataDriverImpl->setMethodCalls($methodCalls);
}

if (null !== $annotatedPrefixes) {
Expand Down

0 comments on commit 3fff156

Please sign in to comment.