Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 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\Translation\DependencyInjection; |
| 13 | |
| 14 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
| 17 | use Symfony\Component\DependencyInjection\Reference; |
| 18 | |
| 19 | /** |
| 20 | * Adds tagged translation.extractor services to translation extractor. |
| 21 | */ |
| 22 | class TranslationExtractorPass implements CompilerPassInterface |
| 23 | { |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 24 | public function process(ContainerBuilder $container) |
| 25 | { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 26 | if (!$container->hasDefinition('translation.extractor')) { |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 27 | return; |
| 28 | } |
| 29 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 30 | $definition = $container->getDefinition('translation.extractor'); |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 31 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 32 | foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) { |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 33 | 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 | } |