Skip to content

Commit dc7ccf1

Browse files
committed
fix(symfony): avoid deprecated translation command probe
1 parent d067679 commit dc7ccf1

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
use PHPStan\PhpDocParser\Parser\PhpDocParser;
7171
use Ramsey\Uuid\Uuid;
7272
use Symfony\AI\McpBundle\McpBundle;
73-
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand;
73+
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand;
7474
use Symfony\Bundle\FrameworkBundle\Controller\ControllerHelper;
7575
use Symfony\Component\Config\FileLocator;
7676
use Symfony\Component\Config\Resource\DirectoryResource;
@@ -89,6 +89,7 @@
8989
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
9090
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
9191
use Symfony\Component\Serializer\Normalizer\NumberNormalizer;
92+
use Symfony\Component\Translation\Command\TranslationExtractCommand;
9293
use Symfony\Component\Uid\AbstractUid;
9394
use Symfony\Component\Validator\Validator\ValidatorInterface;
9495
use Symfony\Component\Yaml\Yaml;
@@ -210,9 +211,10 @@ public function load(array $configs, ContainerBuilder $container): void
210211
$this->registerJsonStreamerConfiguration($container, $loader, $formats, $config);
211212

212213
// TranslationExtractCommand was introduced in framework-bundle/7.3 with the object mapper service.
214+
// Prefer its new namespace on Symfony 8.2 to avoid loading the deprecated FrameworkBundle shim.
213215
// willBeAvailable mirrors FrameworkBundle's own gate: when symfony/object-mapper is in dev-only,
214216
// FrameworkBundle skips object_mapper.php and the "object_mapper" service we alias to does not exist.
215-
if (class_exists(ObjectMapper::class) && class_exists(TranslationExtractCommand::class) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
217+
if (class_exists(ObjectMapper::class) && (class_exists(TranslationExtractCommand::class) || class_exists(FrameworkTranslationExtractCommand::class)) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
216218
$loader->load('state/object_mapper.php');
217219
$loader->load($config['use_symfony_listeners'] ? 'symfony/object_mapper.php' : 'state/object_mapper_processor.php');
218220
}

‎src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use ApiPlatform\Tests\Fixtures\TestBundle\TestBundle;
3030
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
3131
use Doctrine\ORM\OptimisticLockException;
32+
use PHPUnit\Framework\Attributes\PreserveGlobalState;
33+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
3234
use PHPUnit\Framework\TestCase;
3335
use Symfony\AI\McpBundle\McpBundle;
3436
use Symfony\Bundle\SecurityBundle\SecurityBundle;
@@ -184,6 +186,20 @@ private function assertServiceHasTags(string $service, array $tags = []): void
184186
}
185187
}
186188

189+
#[RunInSeparateProcess]
190+
#[PreserveGlobalState(false)]
191+
public function testObjectMapperDoesNotLoadDeprecatedTranslationCommand(): void
192+
{
193+
if (!class_exists(\Symfony\Component\Translation\Command\TranslationExtractCommand::class)) {
194+
self::markTestSkipped('Requires the Symfony 8.2 translation command.');
195+
}
196+
197+
(new ApiPlatformExtension())->load(self::DEFAULT_CONFIG, $this->container);
198+
199+
self::assertTrue($this->container->hasDefinition('api_platform.object_mapper.metadata_factory'));
200+
self::assertFalse(class_exists(\Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand::class, false));
201+
}
202+
187203
public function testCommonConfiguration(): void
188204
{
189205
$config = self::DEFAULT_CONFIG;

0 commit comments

Comments
 (0)