RemovePrivateAliasesPass.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. $compiler = $container->getCompiler();
  27. $formatter = $compiler->getLoggingFormatter();
  28. foreach ($container->getAliases() as $id => $alias) {
  29. if ($alias->isPublic()) {
  30. continue;
  31. }
  32. $container->removeAlias($id);
  33. $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'private alias'));
  34. }
  35. }
  36. }