1 | <?php |
||
19 | final class JWKSet implements JWKSetInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $position = 0; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $keys = []; |
||
30 | |||
31 | public function __construct(array $keys = []) |
||
32 | { |
||
33 | if (array_key_exists('keys', $keys)) { |
||
34 | foreach ($keys['keys'] as $value) { |
||
35 | $this->addKey(new JWK($value)); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function hasKey($index) |
||
44 | { |
||
45 | return array_key_exists($index, $this->keys); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function getKey($index) |
||
52 | { |
||
53 | Assertion::keyExists($this->keys, $index, 'Undefined index.'); |
||
54 | |||
55 | return $this->keys[$index]; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function getKeys() |
||
62 | { |
||
63 | return $this->keys; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function addKey(JWKInterface $key) |
||
70 | { |
||
71 | $this->keys[] = $key; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function removeKey($key) |
||
78 | { |
||
79 | if (isset($this->keys[$key])) { |
||
80 | unset($this->keys[$key]); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | public function jsonSerialize() |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function count($mode = COUNT_NORMAL) |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function current() |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function key() |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function next() |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function rewind() |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function valid() |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function countKeys() |
||
144 | { |
||
145 | return count($this->keys); |
||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | public function offsetExists($offset) |
||
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | public function offsetGet($offset) |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | public function offsetSet($offset, $value) |
||
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | public function offsetUnset($offset) |
||
178 | } |
||
179 |