generated from Firehed/php-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCredential.php
62 lines (55 loc) · 1.79 KB
/
Credential.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace SnapAuth;
use DateTimeImmutable;
class Credential
{
public readonly string $id;
public readonly string $aaguid;
public readonly string $name;
public readonly bool $isActive;
public readonly bool $isBackedUp;
public readonly bool $isBackupEligible;
public readonly bool $isUvInitialized;
public readonly DateTimeImmutable $createdAt;
/**
* @var WebAuthn\AuthenticatorTransport[]
*/
public readonly array $transports;
/**
* @internal The Credential object is part of the SDK, but its constructor
* is not part of SemVer scope.
*
* @phpstan-ignore-next-line
*
* This is the correct shape:
* param array{
* id: string,
* aaguid: string,
* name: string,
* isActive: bool,
* isBackedUp: bool,
* isBackupEligible: bool,
* isUvInitialized: bool,
* createdAt: int,
* transports: string[],
* } $data
*/
public function __construct(array $data)
{
$this->id = $data['id'];
$this->aaguid = $data['aaguid'];
$this->name = $data['name'];
$this->isActive = $data['isActive'];
$this->isBackedUp = $data['isBackedUp'];
$this->isBackupEligible = $data['isBackupEligible'];
$this->isUvInitialized = $data['isUvInitialized'];
$this->createdAt = (new DateTimeImmutable())->setTimestamp($data['createdAt']);
// Ensure array_is_list if anything is filtered
$this->transports = array_values(array_filter(
// If other transport methods are added on the API (which itself
// requires a WebAuthn spec bump), filter out unknown values
array_map(WebAuthn\AuthenticatorTransport::tryFrom(...), $data['transports'])
));
}
}