PurgerFactoryCompilerPass.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass;
  4. use LogicException;
  5. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  6. use Symfony\Component\DependencyInjection\ContainerBuilder;
  7. use Symfony\Component\DependencyInjection\Reference;
  8. use function sprintf;
  9. final class PurgerFactoryCompilerPass implements CompilerPassInterface
  10. {
  11. public const PURGER_FACTORY_TAG = 'doctrine.fixtures.purger_factory';
  12. public function process(ContainerBuilder $container) : void
  13. {
  14. $definition = $container->getDefinition('doctrine.fixtures_load_command');
  15. $taggedServices = $container->findTaggedServiceIds(self::PURGER_FACTORY_TAG);
  16. $purgerFactories = [];
  17. foreach ($taggedServices as $serviceId => $tags) {
  18. foreach ($tags as $tagData) {
  19. if (! isset($tagData['alias'])) {
  20. throw new LogicException(sprintf('Proxy factory "%s" must define an alias', $serviceId));
  21. }
  22. $purgerFactories[$tagData['alias']] = new Reference($serviceId);
  23. }
  24. }
  25. $definition->setArgument(2, $purgerFactories);
  26. }
  27. }