Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / translation / DependencyInjection / TranslationExtractorPass.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\Translation\DependencyInjection;
13
14 use Symfony\Component\DependencyInjection\Reference;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
18
19 /**
20  * Adds tagged translation.extractor services to translation extractor.
21  */
22 class TranslationExtractorPass implements CompilerPassInterface
23 {
24     private $extractorServiceId;
25     private $extractorTag;
26
27     public function __construct($extractorServiceId = 'translation.extractor', $extractorTag = 'translation.extractor')
28     {
29         $this->extractorServiceId = $extractorServiceId;
30         $this->extractorTag = $extractorTag;
31     }
32
33     public function process(ContainerBuilder $container)
34     {
35         if (!$container->hasDefinition($this->extractorServiceId)) {
36             return;
37         }
38
39         $definition = $container->getDefinition($this->extractorServiceId);
40
41         foreach ($container->findTaggedServiceIds($this->extractorTag, true) as $id => $attributes) {
42             if (!isset($attributes[0]['alias'])) {
43                 throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
44             }
45
46             $definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
47         }
48     }
49 }