TemplatingPass.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\AsseticBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. /**
  14. * This pass removes services associated with unused templating engines.
  15. *
  16. * @author Kris Wallsmith <kris@symfony.com>
  17. */
  18. class TemplatingPass implements CompilerPassInterface
  19. {
  20. public function process(ContainerBuilder $container)
  21. {
  22. if (!$container->hasDefinition('assetic.asset_manager')) {
  23. return;
  24. }
  25. $engines = $container->getParameterBag()->resolveValue($container->getParameter('templating.engines'));
  26. if (!in_array('twig', $engines)) {
  27. foreach ($container->findTaggedServiceIds('assetic.templating.twig') as $id => $attr) {
  28. $container->removeDefinition($id);
  29. }
  30. }
  31. if (!in_array('php', $engines)) {
  32. foreach ($container->findTaggedServiceIds('assetic.templating.php') as $id => $attr) {
  33. $container->removeDefinition($id);
  34. }
  35. }
  36. }
  37. }