| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\Denormalizer; |
| 6 |
|
| 7 |
use function assert; |
| 8 |
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
| 9 |
use Webauthn\PublicKeyCredentialRpEntity; |
| 10 |
|
| 11 |
final class PublicKeyCredentialRpEntityDenormalizer implements NormalizerInterface |
| 12 |
{ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function getSupportedTypes(?string $format): array |
| 17 |
{ |
| 18 |
return [ |
| 19 |
PublicKeyCredentialRpEntity::class => true, |
| 20 |
]; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public function normalize(mixed $object, ?string $format = null, array $context = []): ?array |
| 27 |
{ |
| 28 |
assert($object instanceof PublicKeyCredentialRpEntity); |
| 29 |
$data = array_filter( |
| 30 |
[ |
| 31 |
'id' => $object->id, |
| 32 |
'name' => $object->name, |
| 33 |
'icon' => $object->icon, |
| 34 |
], |
| 35 |
static fn (?string $value): bool => ($value !== null && $value !== ''), |
| 36 |
); |
| 37 |
|
| 38 |
return $data === [] ? null : $data; |
| 39 |
} |
| 40 |
|
| 41 |
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool |
| 42 |
{ |
| 43 |
return $data instanceof PublicKeyCredentialRpEntity; |
| 44 |
} |
| 45 |
} |