Skip to content

Commit

Permalink
The TranslatorBag is no TranslatorInterface
Browse files Browse the repository at this point in the history
Leverage union types to properly set up the configuration
  • Loading branch information
SanderVerkuil committed Aug 14, 2024
1 parent ece1c60 commit 528de23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Translator/src/CacheWarmer/TranslationsCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\Translation\TranslatorBagInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\UX\Translator\TranslationsDumper;

/**
Expand All @@ -24,7 +25,7 @@
class TranslationsCacheWarmer implements CacheWarmerInterface
{
public function __construct(
private ?TranslatorBagInterface $translatorBag,
private TranslatorInterface|TranslatorBagInterface|null $translatorBag,
private TranslationsDumper $translationsDumper,
private readonly ?LoggerInterface $logger = null,
) {
Expand All @@ -37,7 +38,7 @@ public function isOptional(): bool

public function warmUp(string $cacheDir, ?string $buildDir = null): array
{
if (null === $this->translatorBag) {
if (!$this->translatorBag instanceof TranslatorBagInterface) {
$this->logger?->warning('Translator bag not available');

return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorBag;
use Symfony\UX\Translator\CacheWarmer\TranslationsCacheWarmer;
use Symfony\UX\Translator\TranslationsDumper;
Expand Down

0 comments on commit 528de23

Please sign in to comment.