Skip to content

Commit

Permalink
minor #88 Ensure forward compatibility with ResolveTargetEntityListen…
Browse files Browse the repository at this point in the history
…er (teohhanhui)

This PR was merged into the 1.4 branch.

Discussion
----------

This should be harmless and will ensure forward compatibility (e.g. when `ResolveTargetEntityListener` decides to subscribe to another event, however unlikely).

Commits
-------

6f6b1cd Ensure forward compatibility with ResolveTargetEntityListener
  • Loading branch information
pamil authored Jun 7, 2019
2 parents 9219474 + 6f6b1cd commit 5cf9ef9
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;

use Doctrine\Common\EventSubscriber;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -44,7 +45,12 @@ public function process(ContainerBuilder $container): void
]);
}

if (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) {
$resolveTargetEntityListenerClass = $container->getParameterBag()->resolveValue($resolveTargetEntityListener->getClass());
if (is_a($resolveTargetEntityListenerClass, EventSubscriber::class, true)) {
if (!$resolveTargetEntityListener->hasTag('doctrine.event_subscriber')) {
$resolveTargetEntityListener->addTag('doctrine.event_subscriber');
}
} elseif (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) {
$resolveTargetEntityListener->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata']);
}
}
Expand Down

0 comments on commit 5cf9ef9

Please sign in to comment.