4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\DependencyInjection;
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;
20 * Adds tagged translation.extractor services to translation extractor.
22 class TranslationExtractorPass implements CompilerPassInterface
24 private $extractorServiceId;
25 private $extractorTag;
27 public function __construct($extractorServiceId = 'translation.extractor', $extractorTag = 'translation.extractor')
29 $this->extractorServiceId = $extractorServiceId;
30 $this->extractorTag = $extractorTag;
33 public function process(ContainerBuilder $container)
35 if (!$container->hasDefinition($this->extractorServiceId)) {
39 $definition = $container->getDefinition($this->extractorServiceId);
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));
46 $definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));