PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.5.1
Defender Security – Malware Scanner, Login Security & Firewall v5.5.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / web-auth / webauthn-lib / src / AuthenticationExtensions / AuthenticationExtensionsClientOutputs.php

AuthenticationExtensionsClientOutputs.php in Defender Security – Malware Scanner, Login Security & Firewall 5.5.1, at vendor/web-auth/webauthn-lib/src/AuthenticationExtensions/AuthenticationExtensionsClientOutputs.php

98 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2014-2021 Spomky-Labs
9 *
10 * This software may be modified and distributed under the terms
11 * of the MIT license. See the LICENSE file for details.
12 */
13
14 namespace Webauthn\AuthenticationExtensions;
15
16 use function array_key_exists;
17 use ArrayIterator;
18 use Assert\Assertion;
19 use function count;
20 use Countable;
21 use Iterator;
22 use IteratorAggregate;
23 use JsonSerializable;
24 use function Safe\json_decode;
25 use function Safe\sprintf;
26
27 class AuthenticationExtensionsClientOutputs implements JsonSerializable, Countable, IteratorAggregate
28 {
29 /**
30 * @var AuthenticationExtension[]
31 */
32 private $extensions = [];
33
34 public function add(AuthenticationExtension $extension): void
35 {
36 $this->extensions[$extension->name()] = $extension;
37 }
38
39 public static function createFromString(string $data): self
40 {
41 $data = json_decode($data, true);
42 Assertion::isArray($data, 'Invalid data');
43
44 return self::createFromArray($data);
45 }
46
47 /**
48 * @param mixed[] $json
49 */
50 public static function createFromArray(array $json): self
51 {
52 $object = new self();
53 foreach ($json as $k => $v) {
54 $object->add(new AuthenticationExtension($k, $v));
55 }
56
57 return $object;
58 }
59
60 public function has(string $key): bool
61 {
62 return array_key_exists($key, $this->extensions);
63 }
64
65 /**
66 * @return mixed
67 */
68 public function get(string $key)
69 {
70 Assertion::true($this->has($key), sprintf('The extension with key "%s" is not available', $key));
71
72 return $this->extensions[$key];
73 }
74
75 /**
76 * @return AuthenticationExtension[]
77 */
78 public function jsonSerialize(): array
79 {
80 return array_map(static function (AuthenticationExtension $object) {
81 return $object->jsonSerialize();
82 }, $this->extensions);
83 }
84
85 /**
86 * @return Iterator<string, AuthenticationExtension>
87 */
88 public function getIterator(): Iterator
89 {
90 return new ArrayIterator($this->extensions);
91 }
92
93 public function count(int $mode = COUNT_NORMAL): int
94 {
95 return count($this->extensions, $mode);
96 }
97 }
98