Skip to content

Commit ac8f0fd

Browse files
committed
Better check whether the translator is supported.
1 parent 93bd43c commit ac8f0fd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Translator/src/DependencyInjection/TranslatorCompilerPass.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@
66

77
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
88
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\Translation\TranslatorBagInterface;
910

1011
class TranslatorCompilerPass implements CompilerPassInterface
1112
{
1213
public function process(ContainerBuilder $container)
1314
{
14-
if (!$container->hasDefinition('translator')) {
15+
if (!$this->hasValidTranslator($container)) {
1516
$container->removeDefinition('ux.translator.cache_warmer.translations_cache_warmer');
1617
}
1718
}
19+
20+
private function hasValidTranslator(ContainerBuilder $containerBuilder): bool
21+
{
22+
if (!$containerBuilder->hasDefinition('translator')) {
23+
return false;
24+
}
25+
26+
$translator = $containerBuilder->getDefinition('translator');
27+
if (!is_subclass_of($translator->getClass(), TranslatorBagInterface::class)) {
28+
return false;
29+
}
30+
return true;
31+
}
1832
}

0 commit comments

Comments
 (0)