c1f05e03ec02c9dd602a89c22b4d7157d2973843
[yaffs-website] / vendor / symfony / dependency-injection / Compiler / AutoAliasServicePass.php
1 <?php
2
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
12 namespace Symfony\Component\DependencyInjection\Compiler;
13
14 use Symfony\Component\DependencyInjection\Alias;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
17
18 /**
19  * Sets a service to be an alias of another one, given a format pattern.
20  */
21 class AutoAliasServicePass implements CompilerPassInterface
22 {
23     /**
24      * {@inheritdoc}
25      */
26     public function process(ContainerBuilder $container)
27     {
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));
32                 }
33
34                 $aliasId = $container->getParameterBag()->resolveValue($tag['format']);
35                 if ($container->hasDefinition($aliasId) || $container->hasAlias($aliasId)) {
36                     $container->setAlias($serviceId, new Alias($aliasId));
37                 }
38             }
39         }
40     }
41 }