Skip to content

Commit 93bd43c

Browse files
committed
If the translator is not available, remove the cache warmer
1 parent d0bb978 commit 93bd43c

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\UX\Translator\DependencyInjection;
6+
7+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
10+
class TranslatorCompilerPass implements CompilerPassInterface
11+
{
12+
public function process(ContainerBuilder $container)
13+
{
14+
if (!$container->hasDefinition('translator')) {
15+
$container->removeDefinition('ux.translator.cache_warmer.translations_cache_warmer');
16+
}
17+
}
18+
}

src/Translator/src/UxTranslatorBundle.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\UX\Translator;
1313

14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1415
use Symfony\Component\HttpKernel\Bundle\Bundle;
16+
use Symfony\UX\Translator\DependencyInjection\TranslatorCompilerPass;
1517

1618
/**
1719
* @author Hugo Alliaume <[email protected]>
@@ -26,4 +28,9 @@ public function getPath(): string
2628
{
2729
return \dirname(__DIR__);
2830
}
31+
32+
public function build(ContainerBuilder $container)
33+
{
34+
$container->addCompilerPass(new TranslatorCompilerPass());
35+
}
2936
}

src/Translator/tests/Kernel/FrameworkAppKernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3838
'secret' => '$ecret',
3939
'test' => true,
4040
'translator' => [
41+
'enabled' => match ($this->environment) {
42+
'test_without_translator' => false,
43+
default => true,
44+
},
4145
'fallbacks' => ['en'],
4246
],
4347
'http_method_override' => false,

src/Translator/tests/UxTranslatorBundleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static function provideKernels()
2222
{
2323
yield 'empty' => [new EmptyAppKernel('test', true)];
2424
yield 'framework' => [new FrameworkAppKernel('test', true)];
25+
yield 'framework without translator' => [new FrameworkAppKernel('test_without_translator', true)];
2526
}
2627

2728
/**

0 commit comments

Comments
 (0)