Skip to content

Instantly share code, notes, and snippets.

@vadim2404
Last active August 29, 2015 13:57
Show Gist options
  • Save vadim2404/9538227 to your computer and use it in GitHub Desktop.
Save vadim2404/9538227 to your computer and use it in GitHub Desktop.
<?php
namespace Acme\DemoBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class DoctrineEntityListenerPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$ems = $container->getParameter('doctrine.entity_managers');
foreach ($ems as $name => $em) {
$container->getDefinition(sprintf('doctrine.orm.%s_configuration', $name))
->addMethodCall('setEntityListenerResolver', [new Reference('acme_demo.doctrine.entity_listener_resolver')])
;
}
$definition = $container->getDefinition('acme_demo.doctrine.entity_listener_resolver');
$services = $container->findTaggedServiceIds('doctrine.entity_listener');
$parameterBag = $container->getParameterBag();
foreach ($services as $service => $attributes) {
$definition->addMethodCall(
'addMapping',
[$parameterBag->resolveValue($container->getDefinition($service)->getClass()), $service]
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment