Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatementSupportManager.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn\AttestationStatement;
6
7 use function array_key_exists;
8 use function sprintf;
9 use Webauthn\Exception\InvalidDataException;
10
11 class AttestationStatementSupportManager
12 {
13 /**
14 * @param AttestationStatementSupport[] $attestationStatementSupports
15 */
16 public function __construct(
17 private array $attestationStatementSupports = []
18 ) {
19 $this->add(new NoneAttestationStatementSupport());
20 foreach ($attestationStatementSupports as $attestationStatementSupport) {
21 if ($attestationStatementSupport instanceof AttestationStatementSupportManagerAwareInterface) {
22 $attestationStatementSupport->setAttestationStatementSupportManager($this);
23 }
24 $this->add($attestationStatementSupport);
25 }
26 }
27
28 /**
29 * @param AttestationStatementSupport[] $attestationStatementSupports
30 */
31 public static function create(array $attestationStatementSupports = []): self
32 {
33 return new self($attestationStatementSupports);
34 }
35
36 public function add(AttestationStatementSupport $attestationStatementSupport): void
37 {
38 $this->attestationStatementSupports[$attestationStatementSupport->name()] = $attestationStatementSupport;
39 }
40
41 public function has(string $name): bool
42 {
43 return array_key_exists($name, $this->attestationStatementSupports);
44 }
45
46 public function get(string $name): AttestationStatementSupport
47 {
48 $this->has($name) || throw InvalidDataException::create($name, sprintf(
49 'The attestation statement format "%s" is not supported.',
50 $name
51 ));
52
53 return $this->attestationStatementSupports[$name];
54 }
55 }