55namespace Drupal \drupal_translation_extractor \Command ;
66
77use Drupal \Core \Extension \ExtensionPathResolver ;
8- use Drupal \drupal_translation_extractor \Translation \Dumper \PoFileDumper ;
98use Drupal \drupal_translation_extractor \Translation \Dumper \PoItem ;
10- use Drupal \drupal_translation_extractor \Translation \TwigExtractor ;
119use Drupal \locale \StringStorageInterface ;
1210use Symfony \Component \Console \Attribute \AsCommand ;
1311use Symfony \Component \Console \Command \Command ;
1816use Symfony \Component \Console \Style \SymfonyStyle ;
1917use Symfony \Component \Translation \Catalogue \MergeOperation ;
2018use Symfony \Component \Translation \Catalogue \TargetOperation ;
19+ use Symfony \Component \Translation \Extractor \ExtractorInterface ;
2120use Symfony \Component \Translation \MessageCatalogue ;
2221use Symfony \Component \Translation \MessageCatalogueInterface ;
23- use Symfony \Component \Translation \Writer \TranslationWriter ;
24- use Twig \Environment ;
22+ use Symfony \Component \Translation \Writer \TranslationWriterInterface ;
2523
2624/**
2725 * Lifted from Symfony's `translation:extract` command.
@@ -43,28 +41,17 @@ final class TranslationExtractCommand extends Command
4341 ];
4442 private const NO_FILL_PREFIX = "\0NoFill \0" ;
4543
46- /**
47- * The writer.
48- */
49- private TranslationWriter $ writer ;
50-
51- /**
52- * The extractor.
53- */
54- private TwigExtractor $ extractor ;
55-
5644 public function __construct (
57- private readonly Environment $ twig ,
5845 private readonly ExtensionPathResolver $ extensionPathResolver ,
5946 private readonly StringStorageInterface $ stringStorage ,
60- PoFileDumper $ poFileDumper ,
47+ private readonly ExtractorInterface $ extractor ,
48+ private readonly TranslationWriterInterface $ writer ,
6149 ) {
62- $ this ->extractor = new TwigExtractor ($ this ->twig );
63-
64- $ this ->writer = new TranslationWriter ();
65- $ this ->writer ->addDumper ('po ' , $ poFileDumper );
66-
6750 parent ::__construct ();
51+
52+ if (!method_exists ($ writer , 'getFormats ' )) {
53+ throw new \InvalidArgumentException (\sprintf ('The writer class "%s" does not implement the "getFormats()" method. ' , $ writer ::class));
54+ }
6855 }
6956
7057 protected function configure (): void
0 commit comments