PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.0
Defender Security – Malware Scanner, Login Security & Firewall v5.6.0
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 / AuthenticationExtensionsClientInputs.php

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

89 lines 2.0 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\sprintf;
25
26 class AuthenticationExtensionsClientInputs implements JsonSerializable, Countable, IteratorAggregate
27 {
28 /**
29 * @var AuthenticationExtension[]
30 */
31 private $extensions = [];
32
33 public function add(AuthenticationExtension $extension): void
34 {
35 $this->extensions[$extension->name()] = $extension;
36 }
37
38 /**
39 * @param mixed[] $json
40 */
41 public static function createFromArray(array $json): self
42 {
43 $object = new self();
44 foreach ($json as $k => $v) {
45 $object->add(new AuthenticationExtension($k, $v));
46 }
47
48 return $object;
49 }
50
51 public function has(string $key): bool
52 {
53 return array_key_exists($key, $this->extensions);
54 }
55
56 /**
57 * @return mixed
58 */
59 public function get(string $key)
60 {
61 Assertion::true($this->has($key), sprintf('The extension with key "%s" is not available', $key));
62
63 return $this->extensions[$key];
64 }
65
66 /**
67 * @return AuthenticationExtension[]
68 */
69 public function jsonSerialize(): array
70 {
71 return array_map(static function (AuthenticationExtension $object) {
72 return $object->jsonSerialize();
73 }, $this->extensions);
74 }
75
76 /**
77 * @return Iterator<string, AuthenticationExtension>
78 */
79 public function getIterator(): Iterator
80 {
81 return new ArrayIterator($this->extensions);
82 }
83
84 public function count(int $mode = COUNT_NORMAL): int
85 {
86 return count($this->extensions, $mode);
87 }
88 }
89