-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
2,370 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/metadata-service/src/Denormalizer/ExtensionDescriptorDenormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webauthn\MetadataService\Denormalizer; | ||
|
||
use Symfony\Component\Serializer\Exception\BadMethodCallException; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Webauthn\MetadataService\Statement\ExtensionDescriptor; | ||
use function array_key_exists; | ||
|
||
final class ExtensionDescriptorDenormalizer implements DenormalizerInterface, DenormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
|
||
private const ALREADY_CALLED = 'EXTENSION_DESCRIPTOR_PREPROCESS_ALREADY_CALLED'; | ||
|
||
public function denormalize(mixed $data, string $type, string $format = null, array $context = []) | ||
{ | ||
if ($this->denormalizer === null) { | ||
throw new BadMethodCallException('Please set a denormalizer before calling denormalize()!'); | ||
} | ||
|
||
if (array_key_exists('fail_if_unknown', $data)) { | ||
$data['failIfUnknown'] = $data['fail_if_unknown']; | ||
unset($data['fail_if_unknown']); | ||
} | ||
|
||
$context[self::ALREADY_CALLED] = true; | ||
|
||
return $this->denormalizer->denormalize($data, $type, $format, $context); | ||
} | ||
|
||
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool | ||
{ | ||
if ($context[self::ALREADY_CALLED] ?? false) { | ||
return false; | ||
} | ||
|
||
return $type === ExtensionDescriptor::class; | ||
} | ||
|
||
/** | ||
* @return array<class-string, bool> | ||
*/ | ||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
ExtensionDescriptor::class => false, | ||
]; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/metadata-service/src/Denormalizer/MetadataStatementSerializerFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webauthn\MetadataService\Denormalizer; | ||
|
||
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; | ||
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; | ||
use Symfony\Component\PropertyInfo\PropertyInfoExtractor; | ||
use Symfony\Component\Serializer\Encoder\JsonEncoder; | ||
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; | ||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
use Symfony\Component\Serializer\Normalizer\UidNormalizer; | ||
use Symfony\Component\Serializer\Serializer; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
final class MetadataStatementSerializerFactory | ||
{ | ||
public static function create(): ?SerializerInterface | ||
{ | ||
foreach (self::getRequiredSerializerClasses() as $class => $package) { | ||
if (! class_exists($class)) { | ||
return null; | ||
} | ||
} | ||
|
||
$denormalizers = [ | ||
new ExtensionDescriptorDenormalizer(), | ||
new UidNormalizer(), | ||
new ArrayDenormalizer(), | ||
new ObjectNormalizer( | ||
propertyTypeExtractor: new PropertyInfoExtractor(typeExtractors: [ | ||
new PhpDocExtractor(), | ||
new ReflectionExtractor(), | ||
]) | ||
), | ||
]; | ||
|
||
return new Serializer($denormalizers, [new JsonEncoder()]); | ||
} | ||
|
||
/** | ||
* @return array<class-string, string> | ||
*/ | ||
private static function getRequiredSerializerClasses(): array | ||
{ | ||
return [ | ||
UidNormalizer::class => 'symfony/serializer', | ||
ArrayDenormalizer::class => 'symfony/serializer', | ||
ObjectNormalizer::class => 'symfony/serializer', | ||
PropertyInfoExtractor::class => 'symfony/serializer', | ||
PhpDocExtractor::class => 'phpdocumentor/reflection-docblock', | ||
ReflectionExtractor::class => 'symfony/serializer', | ||
JsonEncoder::class => 'symfony/serializer', | ||
Serializer::class => 'symfony/serializer', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.