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