4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Compiler;
14 use Symfony\Component\DependencyInjection\Alias;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
19 * Sets a service to be an alias of another one, given a format pattern.
21 class AutoAliasServicePass implements CompilerPassInterface
26 public function process(ContainerBuilder $container)
28 foreach ($container->findTaggedServiceIds('auto_alias') as $serviceId => $tags) {
29 foreach ($tags as $tag) {
30 if (!isset($tag['format'])) {
31 throw new InvalidArgumentException(sprintf('Missing tag information "format" on auto_alias service "%s".', $serviceId));
34 $aliasId = $container->getParameterBag()->resolveValue($tag['format']);
35 if ($container->hasDefinition($aliasId) || $container->hasAlias($aliasId)) {
36 $container->setAlias($serviceId, new Alias($aliasId));