Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Translation\DependencyInjection; Chris@0: Chris@4: use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; Chris@4: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@4: use Symfony\Component\DependencyInjection\Exception\RuntimeException; Chris@0: use Symfony\Component\DependencyInjection\Reference; Chris@0: Chris@0: /** Chris@0: * Adds tagged translation.extractor services to translation extractor. Chris@0: */ Chris@0: class TranslationExtractorPass implements CompilerPassInterface Chris@0: { Chris@0: private $extractorServiceId; Chris@0: private $extractorTag; Chris@0: Chris@0: public function __construct($extractorServiceId = 'translation.extractor', $extractorTag = 'translation.extractor') Chris@0: { Chris@0: $this->extractorServiceId = $extractorServiceId; Chris@0: $this->extractorTag = $extractorTag; Chris@0: } Chris@0: Chris@0: public function process(ContainerBuilder $container) Chris@0: { Chris@0: if (!$container->hasDefinition($this->extractorServiceId)) { Chris@0: return; Chris@0: } Chris@0: Chris@0: $definition = $container->getDefinition($this->extractorServiceId); Chris@0: Chris@0: foreach ($container->findTaggedServiceIds($this->extractorTag, true) as $id => $attributes) { Chris@0: if (!isset($attributes[0]['alias'])) { Chris@0: throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id)); Chris@0: } Chris@0: Chris@4: $definition->addMethodCall('addExtractor', [$attributes[0]['alias'], new Reference($id)]); Chris@0: } Chris@0: } Chris@0: }