TestServiceContainerRealRefPass.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class TestServiceContainerRealRefPass implements CompilerPassInterface
  18. {
  19. public function process(ContainerBuilder $container)
  20. {
  21. if (!$container->hasDefinition('test.private_services_locator')) {
  22. return;
  23. }
  24. $privateContainer = $container->getDefinition('test.private_services_locator');
  25. $definitions = $container->getDefinitions();
  26. $privateServices = $privateContainer->getArgument(0);
  27. foreach ($privateServices as $id => $argument) {
  28. if (isset($definitions[$target = (string) $argument->getValues()[0]])) {
  29. $argument->setValues([new Reference($target)]);
  30. } else {
  31. unset($privateServices[$id]);
  32. }
  33. }
  34. $privateContainer->replaceArgument(0, $privateServices);
  35. }
  36. }