ConverterManagerPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Reference;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  6. /*
  7. * This file is part of the Symfony package.
  8. *
  9. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. /**
  15. * Adds tagged request.param_converter to request.param_converter.manager service
  16. *
  17. * @author Henrik Bjornskov <hb@peytz.dk>
  18. */
  19. class ConverterManagerPass implements CompilerPassInterface
  20. {
  21. /**
  22. * Adds ParamConverters to ConverterManager
  23. *
  24. * @param ContainerBuilder $container
  25. */
  26. public function process(ContainerBuilder $container)
  27. {
  28. if (false === $container->hasDefinition('request.param_converter.manager')) {
  29. return;
  30. }
  31. $definition = $container->getDefinition('request.param_converter.manager');
  32. foreach ($container->findTaggedServiceIds('request.param_converter') as $serviceId => $attributes) {
  33. $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
  34. $definition->addMethodCall('add', array(new Reference($serviceId), $priority));
  35. }
  36. }
  37. }