-
-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #1965 Disable cache warmup when translator is identity translator…
… (SanderVerkuil) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Disable cache warmup when translator is identity translator | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | Fix #1962 | License | MIT If the present `translator` does not implement the `TranslatorBag` interface, which is the case if the framework bundle is enabled and either the form, or the validator are enabled, removes the warmup phase. Commits ------- b75e5d5 Disable cache warmup when translator is identity translator
- Loading branch information
Showing
5 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Translator/src/DependencyInjection/TranslatorCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Symfony\UX\Translator\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Translation\TranslatorBagInterface; | ||
|
||
class TranslatorCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$this->hasValidTranslator($container)) { | ||
$container->removeDefinition('ux.translator.cache_warmer.translations_cache_warmer'); | ||
} | ||
} | ||
|
||
private function hasValidTranslator(ContainerBuilder $containerBuilder): bool | ||
{ | ||
if (!$containerBuilder->hasDefinition('translator')) { | ||
return false; | ||
} | ||
|
||
$translator = $containerBuilder->getDefinition('translator'); | ||
if (!is_subclass_of($translator->getClass(), TranslatorBagInterface::class)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ | |
|
||
namespace Symfony\UX\Translator; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
use Symfony\UX\Translator\DependencyInjection\TranslatorCompilerPass; | ||
|
||
/** | ||
* @author Hugo Alliaume <[email protected]> | ||
|
@@ -26,4 +28,9 @@ public function getPath(): string | |
{ | ||
return \dirname(__DIR__); | ||
} | ||
|
||
public function build(ContainerBuilder $container): void | ||
{ | ||
$container->addCompilerPass(new TranslatorCompilerPass()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters