diff --git a/src/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php b/src/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php index 66ae9012522..a5f7f6c4ee2 100644 --- a/src/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php +++ b/src/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer; use ApiPlatform\Exception\InvalidIdentifierException; +use ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer; use Ramsey\Uuid\Exception\InvalidUuidStringException; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; @@ -26,6 +27,11 @@ */ final class UuidNormalizer implements DenormalizerInterface { + public function __construct() + { + trigger_deprecation('api-platform/core', '2.7', sprintf('The class "%s" will be replaced by "%s".', self::class, UuidUriVariableTransformer::class)); + } + /** * {@inheritdoc} * diff --git a/src/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php b/src/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php index 85367d5e7fe..b6a771af6ad 100644 --- a/src/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php +++ b/src/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer; use ApiPlatform\Exception\InvalidIdentifierException; +use ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Uid\Ulid; @@ -22,6 +23,11 @@ */ final class UlidNormalizer implements DenormalizerInterface { + public function __construct() + { + trigger_deprecation('api-platform/core', '2.7', sprintf('The class "%s" will be replaced by "%s".', self::class, UlidUriVariableTransformer::class)); + } + /** * {@inheritdoc} * diff --git a/src/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizer.php b/src/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizer.php index f84ded89bf0..211d98ba300 100644 --- a/src/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizer.php +++ b/src/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizer.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer; use ApiPlatform\Exception\InvalidIdentifierException; +use ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Uid\Uuid; @@ -22,6 +23,11 @@ */ final class UuidNormalizer implements DenormalizerInterface { + public function __construct() + { + trigger_deprecation('api-platform/core', '2.7', sprintf('The class "%s" will be replaced by "%s".', self::class, UuidUriVariableTransformer::class)); + } + /** * {@inheritdoc} * diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 7a4aab08971..6eeef3281c0 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -201,10 +201,22 @@ private function registerCommonConfiguration(ContainerBuilder $container, array if (class_exists(Uuid::class)) { $loader->load('ramsey_uuid.xml'); + if ($container->hasDefinition('api_platform.identifier.uuid_normalizer')) { + $container->getDefinition('api_platform.identifier.uuid_normalizer') + ->setDeprecated(...$this->buildDeprecationArgs('2.7', 'The "%service_id%" service is deprecated since 2.7 and will be removed in 3.0. Use the "api_platform.ramsey_uuid.uri_variables.transformer.uuid" service instead.')); + } } if (class_exists(AbstractUid::class)) { $loader->load('symfony_uid.xml'); + if ($container->hasDefinition('api_platform.identifier.symfony_ulid_normalizer')) { + $container->getDefinition('api_platform.identifier.symfony_ulid_normalizer') + ->setDeprecated(...$this->buildDeprecationArgs('2.7', 'The "%service_id%" service is deprecated since 2.7 and will be removed in 3.0. Use the "api_platform.symfony.uri_variables.transformer.ulid" service instead.')); + } + if ($container->hasDefinition('api_platform.identifier.symfony_uuid_normalizer')) { + $container->getDefinition('api_platform.identifier.symfony_uuid_normalizer') + ->setDeprecated(...$this->buildDeprecationArgs('2.7', 'The "%service_id%" service is deprecated since 2.7 and will be removed in 3.0. Use the "api_platform.symfony.uri_variables.transformer.uuid" service instead.')); + } } $container->setParameter('api_platform.metadata_backward_compatibility_layer', $config['metadata_backward_compatibility_layer']); diff --git a/tests/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizerTest.php b/tests/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizerTest.php index 3cd3cf99136..f0d43c58f69 100644 --- a/tests/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizerTest.php +++ b/tests/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizerTest.php @@ -17,11 +17,18 @@ use ApiPlatform\Exception\InvalidIdentifierException; use PHPUnit\Framework\TestCase; use Ramsey\Uuid\Uuid; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; +/** + * @group legacy + */ class UuidNormalizerTest extends TestCase { + use ExpectDeprecationTrait; + public function testDenormalizeUuid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".'); $uuid = Uuid::uuid4(); $normalizer = new UuidNormalizer(); $this->assertTrue($normalizer->supportsDenormalization($uuid->toString(), Uuid::class)); @@ -30,6 +37,7 @@ public function testDenormalizeUuid() public function testNoSupportDenormalizeUuid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".'); $uuid = 'notanuuid'; $normalizer = new UuidNormalizer(); $this->assertFalse($normalizer->supportsDenormalization($uuid, '')); @@ -37,6 +45,7 @@ public function testNoSupportDenormalizeUuid() public function testFailDenormalizeUuid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".'); $this->expectException(InvalidIdentifierException::class); $uuid = 'notanuuid'; @@ -47,6 +56,7 @@ public function testFailDenormalizeUuid() public function testDoNotSupportNotString() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".'); $uuid = Uuid::uuid4(); $normalizer = new UuidNormalizer(); $this->assertFalse($normalizer->supportsDenormalization($uuid, Uuid::class)); diff --git a/tests/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizerTest.php b/tests/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizerTest.php index 170fab26d65..24e466dfb07 100644 --- a/tests/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizerTest.php +++ b/tests/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizerTest.php @@ -16,11 +16,17 @@ use ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer; use ApiPlatform\Exception\InvalidIdentifierException; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Uid\AbstractUid; use Symfony\Component\Uid\Ulid; +/** + * @group legacy + */ final class UlidNormalizerTest extends TestCase { + use ExpectDeprecationTrait; + protected function setUp(): void { if (!class_exists(AbstractUid::class)) { @@ -30,6 +36,7 @@ protected function setUp(): void public function testDenormalizeUlid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".'); $ulid = new Ulid(); $normalizer = new UlidNormalizer(); $this->assertTrue($normalizer->supportsDenormalization($ulid->__toString(), Ulid::class)); @@ -38,6 +45,7 @@ public function testDenormalizeUlid() public function testNoSupportDenormalizeUlid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".'); $ulid = 'notanulid'; $normalizer = new UlidNormalizer(); $this->assertFalse($normalizer->supportsDenormalization($ulid, '')); @@ -45,6 +53,7 @@ public function testNoSupportDenormalizeUlid() public function testFailDenormalizeUlid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".'); $this->expectException(InvalidIdentifierException::class); $ulid = 'notanulid'; @@ -55,6 +64,7 @@ public function testFailDenormalizeUlid() public function testDoNotSupportNotString() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".'); $ulid = new Ulid(); $normalizer = new UlidNormalizer(); $this->assertFalse($normalizer->supportsDenormalization($ulid, Ulid::class)); diff --git a/tests/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizerTest.php b/tests/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizerTest.php index 32c124a72ad..0f1278cf05f 100644 --- a/tests/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizerTest.php +++ b/tests/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizerTest.php @@ -16,11 +16,17 @@ use ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer; use ApiPlatform\Exception\InvalidIdentifierException; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Uid\AbstractUid; use Symfony\Component\Uid\Uuid; +/** + * @group legacy + */ final class UuidNormalizerTest extends TestCase { + use ExpectDeprecationTrait; + protected function setUp(): void { if (!class_exists(AbstractUid::class)) { @@ -30,6 +36,8 @@ protected function setUp(): void public function testDenormalizeUuid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".'); + $uuid = Uuid::v4(); $normalizer = new UuidNormalizer(); $this->assertTrue($normalizer->supportsDenormalization($uuid->__toString(), Uuid::class)); @@ -38,6 +46,7 @@ public function testDenormalizeUuid() public function testNoSupportDenormalizeUuid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".'); $uuid = 'notanuuid'; $normalizer = new UuidNormalizer(); $this->assertFalse($normalizer->supportsDenormalization($uuid, '')); @@ -45,6 +54,7 @@ public function testNoSupportDenormalizeUuid() public function testFailDenormalizeUuid() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".'); $this->expectException(InvalidIdentifierException::class); $uuid = 'notanuuid'; @@ -55,6 +65,7 @@ public function testFailDenormalizeUuid() public function testDoNotSupportNotString() { + $this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".'); $uuid = Uuid::v4(); $normalizer = new UuidNormalizer(); $this->assertFalse($normalizer->supportsDenormalization($uuid, Uuid::class));