DataCollectorTranslatorPass.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\Translation\TranslatorBagInterface;
  14. /**
  15. * @author Christian Flothmann <christian.flothmann@sensiolabs.de>
  16. */
  17. class DataCollectorTranslatorPass implements CompilerPassInterface
  18. {
  19. public function process(ContainerBuilder $container): void
  20. {
  21. if (!$container->has('translator')) {
  22. return;
  23. }
  24. $translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
  25. if (!is_subclass_of($translatorClass, TranslatorBagInterface::class)) {
  26. $container->removeDefinition('translator.data_collector');
  27. $container->removeDefinition('data_collector.translation');
  28. }
  29. }
  30. }