Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FWB][Serializer][Form][Validator] Uid integration #36317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
UidNormalizer
  • Loading branch information
Guillaume Pédelagrabe committed Apr 8, 2020
commit 343f145fc4075a8b5836ae225eaf909676401312
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<tag name="serializer.normalizer" priority="-890" />
</service>

<service id="serializer.normalizer.uuid" class="Symfony\Component\Serializer\Normalizer\UuidNormalizer">
<service id="serializer.normalizer.uid" class="Symfony\Component\Serializer\Normalizer\UidNormalizer">
<argument>%kernel.debug%</argument>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove this argument

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<!-- Run before serializer.normalizer.object -->
<tag name="serializer.normalizer" priority="-90" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Uid\AbstractUid;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Uid\Uuid;

class UuidNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
class UidNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
{
public function normalize($object, string $format = null, array $context = [])
{
if (!$object instanceof Uuid) {
if (!$object instanceof AbstractUid) {
throw new InvalidArgumentException('The object must be an instance of "\Symfony\Component\Uid\Uuid".');
}

Expand All @@ -19,25 +21,25 @@ public function normalize($object, string $format = null, array $context = [])

public function supportsNormalization($data, string $format = null)
{
return $data instanceof Uuid;
return $data instanceof AbstractUid;
}

public function denormalize($data, string $type, string $format = null, array $context = [])
{
try {
$uuid = Uuid::fromString($data);
$uid = Ulid::class === $type ? Ulid::fromString($data) : Uuid::fromString($data);
} catch (\InvalidArgumentException $exception) {
throw new NotNormalizableValueException('The data is not a valid UUID string representation.');
throw new NotNormalizableValueException('The data is not a valid UUID or ULID string representation.');
}

return $uuid;
return $uid;
}

public function supportsDenormalization($data, string $type, string $format = null)
{
$class = new \ReflectionClass($type);

return $class->isSubclassOf(Uuid::class);
return $class->isSubclassOf(AbstractUid::class);
}

public function hasCacheableSupportsMethod(): bool
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.