CacheSchemaSubscriberPass.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;
  3. use Symfony\Component\Cache\Adapter\PdoAdapter;
  4. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  5. use Symfony\Component\DependencyInjection\ContainerBuilder;
  6. use Symfony\Component\DependencyInjection\Reference;
  7. /**
  8. * Injects PdoAdapter into its schema subscriber.
  9. *
  10. * Must be run later after ResolveChildDefinitionsPass.
  11. */
  12. class CacheSchemaSubscriberPass implements CompilerPassInterface
  13. {
  14. /**
  15. * {@inheritDoc}
  16. */
  17. public function process(ContainerBuilder $container)
  18. {
  19. $subscriberId = 'doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber';
  20. if (! $container->hasDefinition($subscriberId)) {
  21. return;
  22. }
  23. $cacheAdaptersReferences = [];
  24. foreach ($container->getDefinitions() as $id => $definition) {
  25. if ($definition->isAbstract() || $definition->isSynthetic()) {
  26. continue;
  27. }
  28. if ($definition->getClass() !== PdoAdapter::class) {
  29. continue;
  30. }
  31. $cacheAdaptersReferences[] = new Reference($id);
  32. }
  33. $container->getDefinition($subscriberId)
  34. ->replaceArgument(0, $cacheAdaptersReferences);
  35. }
  36. }