MissingExtensionSuggestorPass.php 1.4 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 Twig\Extra\TwigExtraBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. use Twig\Environment;
  15. class MissingExtensionSuggestorPass implements CompilerPassInterface
  16. {
  17. public function process(ContainerBuilder $container)
  18. {
  19. if ($container->getParameter('kernel.debug')) {
  20. $twigDefinition = $container->getDefinition('twig');
  21. $twigDefinition
  22. ->addMethodCall('registerUndefinedFilterCallback', [[new Reference('twig.missing_extension_suggestor'), 'suggestFilter']])
  23. ->addMethodCall('registerUndefinedFunctionCallback', [[new Reference('twig.missing_extension_suggestor'), 'suggestFunction']])
  24. ;
  25. // this method was added in Twig 3.2
  26. if (method_exists(Environment::class, 'registerUndefinedTokenParserCallback')) {
  27. $twigDefinition->addMethodCall('registerUndefinedTokenParserCallback', [[new Reference('twig.missing_extension_suggestor'), 'suggestTag']]);
  28. }
  29. }
  30. }
  31. }