Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}
*
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -30,13 +37,15 @@ 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, ''));
}

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';
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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));
Expand All @@ -38,13 +45,15 @@ 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, ''));
}

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';
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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));
Expand All @@ -38,13 +46,15 @@ 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, ''));
}

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';
Expand All @@ -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));
Expand Down