AddFormGuessersPass.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  3. /*
  4. * This file is part of the Symfony package.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * Adds all services with the tag "form.guesser" as constructor argument of the
  16. * "form.factory" service
  17. *
  18. * @author Bernhard Schussek <bernhard.schussek@symfony.com>
  19. */
  20. class AddFormGuessersPass implements CompilerPassInterface
  21. {
  22. public function process(ContainerBuilder $container)
  23. {
  24. if (!$container->hasDefinition('form.factory')) {
  25. return;
  26. }
  27. $guessers = array();
  28. foreach ($container->findTaggedServiceIds('form.guesser') as $serviceId => $tag) {
  29. $guessers[] = new Reference($serviceId);
  30. }
  31. $container->getDefinition('form.factory')->setArgument(2, $guessers);
  32. }
  33. }