Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection\Compiler; Chris@0: Chris@0: use Symfony\Component\DependencyInjection\Alias; Chris@0: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@0: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@0: Chris@0: /** Chris@0: * Sets a service to be an alias of another one, given a format pattern. Chris@0: */ Chris@0: class AutoAliasServicePass implements CompilerPassInterface Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function process(ContainerBuilder $container) Chris@0: { Chris@0: foreach ($container->findTaggedServiceIds('auto_alias') as $serviceId => $tags) { Chris@0: foreach ($tags as $tag) { Chris@0: if (!isset($tag['format'])) { Chris@0: throw new InvalidArgumentException(sprintf('Missing tag information "format" on auto_alias service "%s".', $serviceId)); Chris@0: } Chris@0: Chris@0: $aliasId = $container->getParameterBag()->resolveValue($tag['format']); Chris@0: if ($container->hasDefinition($aliasId) || $container->hasAlias($aliasId)) { Chris@14: $container->setAlias($serviceId, new Alias($aliasId, true)); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: }