Skip to content

Commit 6f21a40

Browse files
committed
require the writer to implement getFormats() in the translation:extract
1 parent a8e3976 commit 6f21a40

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Command/TranslationUpdateCommand.php

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function __construct(TranslationWriterInterface $writer, TranslationReade
6464
{
6565
parent::__construct();
6666

67+
if (!method_exists($writer, 'getFormats')) {
68+
throw new \InvalidArgumentException(sprintf('The writer class "%s" does not implement the "getFormats()" method.', $writer::class));
69+
}
70+
6771
$this->writer = $writer;
6872
$this->reader = $reader;
6973
$this->extractor = $extractor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
class TranslationUpdateCommandPass implements CompilerPassInterface
18+
{
19+
public function process(ContainerBuilder $container): void
20+
{
21+
if (!$container->hasDefinition('console.command.translation_extract')) {
22+
return;
23+
}
24+
25+
$translationWriterClass = $container->getParameterBag()->resolveValue($container->findDefinition('translation.writer')->getClass());
26+
27+
if (!method_exists($translationWriterClass, 'getFormats')) {
28+
$container->removeDefinition('console.command.translation_extract');
29+
}
30+
}
31+
}

FrameworkBundle.php

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
2121
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2222
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
23+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationUpdateCommandPass;
2324
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2425
use Symfony\Bundle\FrameworkBundle\DependencyInjection\VirtualRequestStackPass;
2526
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@@ -193,6 +194,7 @@ public function build(ContainerBuilder $container)
193194
// must be registered after MonologBundle's LoggerChannelPass
194195
$container->addCompilerPass(new ErrorLoggerCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
195196
$container->addCompilerPass(new VirtualRequestStackPass());
197+
$container->addCompilerPass(new TranslationUpdateCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
196198

197199
if ($container->getParameter('kernel.debug')) {
198200
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);

0 commit comments

Comments
 (0)