blob: ee7c47ae4e6f91b6d45a3c5297c3a9b146a62182 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?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
12namespace Symfony\Component\Translation\DependencyInjection;
13
14use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15use Symfony\Component\DependencyInjection\ContainerBuilder;
16use Symfony\Component\DependencyInjection\Exception\RuntimeException;
17use Symfony\Component\DependencyInjection\Reference;
18
19/**
20 * Adds tagged translation.extractor services to translation extractor.
21 */
22class TranslationExtractorPass implements CompilerPassInterface
23{
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020024 public function process(ContainerBuilder $container)
25 {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010026 if (!$container->hasDefinition('translation.extractor')) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020027 return;
28 }
29
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010030 $definition = $container->getDefinition('translation.extractor');
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020031
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010032 foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020033 if (!isset($attributes[0]['alias'])) {
34 throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
35 }
36
37 $definition->addMethodCall('addExtractor', [$attributes[0]['alias'], new Reference($id)]);
38 }
39 }
40}