菜谱项目

ControllerArgumentValueResolverPass.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Component\HttpKernel\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. /**
  16. * Gathers and configures the argument value resolvers.
  17. *
  18. * @author Iltar van der Berg <kjarli@gmail.com>
  19. */
  20. class ControllerArgumentValueResolverPass implements CompilerPassInterface
  21. {
  22. use PriorityTaggedServiceTrait;
  23. private $argumentResolverService;
  24. private $argumentValueResolverTag;
  25. public function __construct($argumentResolverService = 'argument_resolver', $argumentValueResolverTag = 'controller.argument_value_resolver')
  26. {
  27. $this->argumentResolverService = $argumentResolverService;
  28. $this->argumentValueResolverTag = $argumentValueResolverTag;
  29. }
  30. public function process(ContainerBuilder $container)
  31. {
  32. if (!$container->hasDefinition($this->argumentResolverService)) {
  33. return;
  34. }
  35. $container
  36. ->getDefinition($this->argumentResolverService)
  37. ->replaceArgument(1, new IteratorArgument($this->findAndSortTaggedServices($this->argumentValueResolverTag, $container)))
  38. ;
  39. }
  40. }