From 24890b62b703e14294f2c1a88523a6ef4575b4f2 Mon Sep 17 00:00:00 2001 From: Ellis Benjamin Date: Sat, 17 Sep 2022 14:22:04 +0200 Subject: [PATCH 1/4] fix(symfony): missing deprecations related to Ulid and Uuid normalizers in constructors and dependency injection --- .../RamseyUuid/Identifier/Normalizer/UuidNormalizer.php | 6 ++++++ .../Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php | 6 ++++++ .../Bridge/Symfony/Identifier/Normalizer/UuidNormalizer.php | 6 ++++++ src/Symfony/Bundle/Resources/config/ramsey_uuid.xml | 1 + src/Symfony/Bundle/Resources/config/symfony_uid.xml | 2 ++ 5 files changed, 21 insertions(+) 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/Resources/config/ramsey_uuid.xml b/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml index 3d34bb37ced..d1e46b56148 100644 --- a/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml +++ b/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml @@ -7,6 +7,7 @@ + The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer". diff --git a/src/Symfony/Bundle/Resources/config/symfony_uid.xml b/src/Symfony/Bundle/Resources/config/symfony_uid.xml index b03b37058f2..7bb3c484cea 100644 --- a/src/Symfony/Bundle/Resources/config/symfony_uid.xml +++ b/src/Symfony/Bundle/Resources/config/symfony_uid.xml @@ -7,10 +7,12 @@ + The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer". + The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer". From 9fc9f294f6a63e1ed1e619fede62250e5f44ec35 Mon Sep 17 00:00:00 2001 From: Ellis Benjamin Date: Sat, 17 Sep 2022 14:42:49 +0200 Subject: [PATCH 2/4] fix(symfony): missing deprecations related to Ulid and Uuid normalizers in constructors and dependency injection --- .../DependencyInjection/ApiPlatformExtension.php | 12 ++++++++++++ src/Symfony/Bundle/Resources/config/ramsey_uuid.xml | 1 - src/Symfony/Bundle/Resources/config/symfony_uid.xml | 1 - 3 files changed, 12 insertions(+), 2 deletions(-) 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/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml b/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml index d1e46b56148..3d34bb37ced 100644 --- a/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml +++ b/src/Symfony/Bundle/Resources/config/ramsey_uuid.xml @@ -7,7 +7,6 @@ - The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer". diff --git a/src/Symfony/Bundle/Resources/config/symfony_uid.xml b/src/Symfony/Bundle/Resources/config/symfony_uid.xml index 7bb3c484cea..d3a992b4e03 100644 --- a/src/Symfony/Bundle/Resources/config/symfony_uid.xml +++ b/src/Symfony/Bundle/Resources/config/symfony_uid.xml @@ -12,7 +12,6 @@ - The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer". From 1518e28e4b8ed5088fb5e93fad01fce0fbee28e2 Mon Sep 17 00:00:00 2001 From: Ellis Benjamin Date: Sat, 17 Sep 2022 14:47:19 +0200 Subject: [PATCH 3/4] fix tests --- src/Symfony/Bundle/Resources/config/symfony_uid.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bundle/Resources/config/symfony_uid.xml b/src/Symfony/Bundle/Resources/config/symfony_uid.xml index d3a992b4e03..b03b37058f2 100644 --- a/src/Symfony/Bundle/Resources/config/symfony_uid.xml +++ b/src/Symfony/Bundle/Resources/config/symfony_uid.xml @@ -7,7 +7,6 @@ - The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer". From 6c21514c12fd6e9f908a899614e89e71a18fe6ec Mon Sep 17 00:00:00 2001 From: soyuka Date: Mon, 19 Sep 2022 16:06:58 +0200 Subject: [PATCH 4/4] test: expect deprecation --- .../Identifier/Normalizer/UuidNormalizerTest.php | 10 ++++++++++ .../Identifier/Normalizer/UlidNormalizerTest.php | 10 ++++++++++ .../Identifier/Normalizer/UuidNormalizerTest.php | 11 +++++++++++ 3 files changed, 31 insertions(+) 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));