Chris@14
|
1 <?php
|
Chris@14
|
2
|
Chris@14
|
3 /*
|
Chris@14
|
4 * This file is part of the Symfony package.
|
Chris@14
|
5 *
|
Chris@14
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@14
|
7 *
|
Chris@14
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@14
|
9 * file that was distributed with this source code.
|
Chris@14
|
10 */
|
Chris@14
|
11
|
Chris@14
|
12 namespace Symfony\Component\Translation\DependencyInjection;
|
Chris@14
|
13
|
Chris@17
|
14 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
Chris@17
|
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
|
Chris@17
|
16 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
Chris@14
|
17 use Symfony\Component\DependencyInjection\Reference;
|
Chris@14
|
18
|
Chris@14
|
19 /**
|
Chris@14
|
20 * Adds tagged translation.extractor services to translation extractor.
|
Chris@14
|
21 */
|
Chris@14
|
22 class TranslationExtractorPass implements CompilerPassInterface
|
Chris@14
|
23 {
|
Chris@14
|
24 private $extractorServiceId;
|
Chris@14
|
25 private $extractorTag;
|
Chris@14
|
26
|
Chris@14
|
27 public function __construct($extractorServiceId = 'translation.extractor', $extractorTag = 'translation.extractor')
|
Chris@14
|
28 {
|
Chris@14
|
29 $this->extractorServiceId = $extractorServiceId;
|
Chris@14
|
30 $this->extractorTag = $extractorTag;
|
Chris@14
|
31 }
|
Chris@14
|
32
|
Chris@14
|
33 public function process(ContainerBuilder $container)
|
Chris@14
|
34 {
|
Chris@14
|
35 if (!$container->hasDefinition($this->extractorServiceId)) {
|
Chris@14
|
36 return;
|
Chris@14
|
37 }
|
Chris@14
|
38
|
Chris@14
|
39 $definition = $container->getDefinition($this->extractorServiceId);
|
Chris@14
|
40
|
Chris@14
|
41 foreach ($container->findTaggedServiceIds($this->extractorTag, true) as $id => $attributes) {
|
Chris@14
|
42 if (!isset($attributes[0]['alias'])) {
|
Chris@14
|
43 throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
|
Chris@14
|
44 }
|
Chris@14
|
45
|
Chris@17
|
46 $definition->addMethodCall('addExtractor', [$attributes[0]['alias'], new Reference($id)]);
|
Chris@14
|
47 }
|
Chris@14
|
48 }
|
Chris@14
|
49 }
|