FragmentRendererPass.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. @trigger_error('The '.__NAMESPACE__.'\FragmentRendererPass class is deprecated since Symfony 2.7 and will be removed in 3.0. Use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass instead.', E_USER_DEPRECATED);
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * Adds services tagged kernel.fragment_renderer as HTTP content rendering strategies.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. *
  20. * @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass instead.
  21. */
  22. class FragmentRendererPass implements CompilerPassInterface
  23. {
  24. public function process(ContainerBuilder $container)
  25. {
  26. if (false === $container->hasDefinition('fragment.handler')) {
  27. return;
  28. }
  29. $definition = $container->getDefinition('fragment.handler');
  30. foreach (array_keys($container->findTaggedServiceIds('kernel.fragment_renderer')) as $id) {
  31. // We must assume that the class value has been correctly filled, even if the service is created by a factory
  32. $class = $container->getDefinition($id)->getClass();
  33. $interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';
  34. if (!is_subclass_of($class, $interface)) {
  35. throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
  36. }
  37. $definition->addMethodCall('addRenderer', array(new Reference($id)));
  38. }
  39. }
  40. }