ConverterManagerPass.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 = 0;
  34. if (isset($attributes['priority'])) {
  35. $priority = (integer) $attributes['priority'];
  36. }
  37. $definition->addMethodCall('add', array(new Reference($serviceId), $priority));
  38. }
  39. }
  40. }