FixturesCompilerPass.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass;
  4. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  5. use Symfony\Component\DependencyInjection\ContainerBuilder;
  6. use Symfony\Component\DependencyInjection\Reference;
  7. final class FixturesCompilerPass implements CompilerPassInterface
  8. {
  9. public const FIXTURE_TAG = 'doctrine.fixture.orm';
  10. public function process(ContainerBuilder $container) : void
  11. {
  12. $definition = $container->getDefinition('doctrine.fixtures.loader');
  13. $taggedServices = $container->findTaggedServiceIds(self::FIXTURE_TAG);
  14. $fixtures = [];
  15. foreach ($taggedServices as $serviceId => $tags) {
  16. $groups = [];
  17. foreach ($tags as $tagData) {
  18. if (! isset($tagData['group'])) {
  19. continue;
  20. }
  21. $groups[] = $tagData['group'];
  22. }
  23. $fixtures[] = [
  24. 'fixture' => new Reference($serviceId),
  25. 'groups' => $groups,
  26. ];
  27. }
  28. $definition->addMethodCall('addFixtures', [$fixtures]);
  29. }
  30. }