LoggingTranslatorPass.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
  16. */
  17. class LoggingTranslatorPass implements CompilerPassInterface
  18. {
  19. public function process(ContainerBuilder $container)
  20. {
  21. if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
  22. return;
  23. }
  24. if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
  25. $translatorAlias = $container->getAlias('translator');
  26. $definition = $container->getDefinition((string) $translatorAlias);
  27. $class = $container->getParameterBag()->resolveValue($definition->getClass());
  28. if (is_subclass_of($class, 'Symfony\Component\Translation\TranslatorInterface') && is_subclass_of($class, 'Symfony\Component\Translation\TranslatorBagInterface')) {
  29. $container->getDefinition('translator.logging')->setDecoratedService('translator');
  30. $container->getDefinition('translation.warmer')->replaceArgument(0, new Reference('translator.logging.inner'));
  31. }
  32. }
  33. }
  34. }