AddFieldFactoryGuessersPass.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.field_factory_guesser" as argument
  16. * to the "form.field_factory" service
  17. *
  18. * @author Bernhard Schussek <bernhard.schussek@symfony.com>
  19. */
  20. class AddFieldFactoryGuessersPass implements CompilerPassInterface
  21. {
  22. public function process(ContainerBuilder $container)
  23. {
  24. if (!$container->hasDefinition('form.field_factory')) {
  25. return;
  26. }
  27. $guessers = array_map(function($id) {
  28. return new Reference($id);
  29. }, array_keys($container->findTaggedServiceIds('form.field_factory.guesser')));
  30. $container->getDefinition('form.field_factory')->replaceArgument(0, $guessers);
  31. }
  32. }