RemovePrivateAliasesPass.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. /**
  13. * Remove private aliases from the container. They were only used to establish
  14. * dependencies between services, and these dependencies have been resolved in
  15. * one of the previous passes.
  16. *
  17. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18. */
  19. class RemovePrivateAliasesPass implements CompilerPassInterface
  20. {
  21. /**
  22. * Removes private aliases from the ContainerBuilder.
  23. */
  24. public function process(ContainerBuilder $container)
  25. {
  26. foreach ($container->getAliases() as $id => $alias) {
  27. if ($alias->isPublic()) {
  28. continue;
  29. }
  30. $container->removeAlias($id);
  31. $container->log($this, sprintf('Removed service "%s"; reason: private alias.', $id));
  32. }
  33. }
  34. }