Skip to content

Commit e64bc06

Browse files
zoliszabonicolas-grekas
authored andcommitted
[Translation] Make the extractor alias optional
1 parent 125608d commit e64bc06

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
7.4
55
---
66

7+
* Make the extractor alias optional
78
* Deprecate `TranslatableMessage::__toString`
89
* Add `Symfony\Component\Translation\StaticMessage`
910

DependencyInjection/TranslationExtractorPass.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1716
use Symfony\Component\DependencyInjection\Reference;
1817

1918
/**
@@ -30,11 +29,7 @@ public function process(ContainerBuilder $container): void
3029
$definition = $container->getDefinition('translation.extractor');
3130

3231
foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
33-
if (!isset($attributes[0]['alias'])) {
34-
throw new RuntimeException(\sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
35-
}
36-
37-
$definition->addMethodCall('addExtractor', [$attributes[0]['alias'], new Reference($id)]);
32+
$definition->addMethodCall('addExtractor', [$attributes[0]['alias'] ?? $id, new Reference($id)]);
3833
}
3934
}
4035
}

Tests/DependencyInjection/TranslationExtractorPassTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1716
use Symfony\Component\DependencyInjection\Reference;
1817
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
1918

@@ -50,15 +49,13 @@ public function testProcessNoDefinitionFound()
5049
public function testProcessMissingAlias()
5150
{
5251
$container = new ContainerBuilder();
53-
$container->register('translation.extractor');
52+
$extractorDefinition = $container->register('translation.extractor');
5453
$container->register('foo.id')
5554
->addTag('translation.extractor', []);
5655

5756
$translationDumperPass = new TranslationExtractorPass();
58-
59-
$this->expectException(RuntimeException::class);
60-
$this->expectExceptionMessage('The alias for the tag "translation.extractor" of service "foo.id" must be set.');
61-
6257
$translationDumperPass->process($container);
58+
59+
$this->assertEquals([['addExtractor', ['foo.id', new Reference('foo.id')]]], $extractorDefinition->getMethodCalls());
6360
}
6461
}

0 commit comments

Comments
 (0)