From eee89780c485b38c23e089ff577e0e29e77e920d Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Thu, 1 Oct 2026 12:42:53 -0400 Subject: [PATCH] fix(symfony): avoid deprecated translation command probe --- .../ApiPlatformExtension.php | 5 +++-- .../ApiPlatformExtensionTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index c5efef3a66..8a3185acc5 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -70,7 +70,7 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use Ramsey\Uuid\Uuid; use Symfony\AI\McpBundle\McpBundle; -use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand; +use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand; use Symfony\Bundle\FrameworkBundle\Controller\ControllerHelper; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Resource\DirectoryResource; @@ -89,6 +89,7 @@ use Symfony\Component\ObjectMapper\ObjectMapperInterface; use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; use Symfony\Component\Serializer\Normalizer\NumberNormalizer; +use Symfony\Component\Translation\Command\TranslationExtractCommand; use Symfony\Component\Uid\AbstractUid; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Yaml\Yaml; @@ -212,7 +213,7 @@ public function load(array $configs, ContainerBuilder $container): void // TranslationExtractCommand was introduced in framework-bundle/7.3 with the object mapper service. // willBeAvailable mirrors FrameworkBundle's own gate: when symfony/object-mapper is in dev-only, // FrameworkBundle skips object_mapper.php and the "object_mapper" service we alias to does not exist. - if (class_exists(ObjectMapper::class) && class_exists(TranslationExtractCommand::class) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) { + if (class_exists(ObjectMapper::class) && (class_exists(TranslationExtractCommand::class) || class_exists(FrameworkTranslationExtractCommand::class)) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) { $loader->load('state/object_mapper.php'); $loader->load($config['use_symfony_listeners'] ? 'symfony/object_mapper.php' : 'state/object_mapper_processor.php'); } diff --git a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 6a0b2f737d..0f3fe8a609 100644 --- a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -29,8 +29,11 @@ use ApiPlatform\Tests\Fixtures\TestBundle\TestBundle; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\ORM\OptimisticLockException; +use PHPUnit\Framework\Attributes\PreserveGlobalState; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Symfony\AI\McpBundle\McpBundle; +use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -38,6 +41,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter; +use Symfony\Component\Translation\Command\TranslationExtractCommand; class ApiPlatformExtensionTest extends TestCase { @@ -184,6 +188,20 @@ private function assertServiceHasTags(string $service, array $tags = []): void } } + #[RunInSeparateProcess] + #[PreserveGlobalState(false)] + public function testObjectMapperDoesNotLoadDeprecatedTranslationCommand(): void + { + if (!class_exists(TranslationExtractCommand::class)) { + self::markTestSkipped('Requires the Symfony 8.2 translation command.'); + } + + (new ApiPlatformExtension())->load(self::DEFAULT_CONFIG, $this->container); + + self::assertTrue($this->container->hasDefinition('api_platform.object_mapper.metadata_factory')); + self::assertFalse(class_exists(FrameworkTranslationExtractCommand::class, false)); + } + public function testCommonConfiguration(): void { $config = self::DEFAULT_CONFIG;