for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 Spomky-Labs
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Object;
use Assert\Assertion;
/**
* Class JWKSet.
final class JWKSet implements JWKSetInterface
{
* @var int
private $position = 0;
* @var array
protected $keys = [];
public function __construct(array $keys = [])
if (array_key_exists('keys', $keys)) {
foreach ($keys['keys'] as $value) {
$key = new JWK($value);
$this->keys[] = $key;
}
* {@inheritdoc}
public function getKey($index)
Assertion::keyExists($this->keys, $index, 'Undefined index.');
return $this->keys[$index];
public function getKeys()
return $this->keys;
public function addKey(JWKInterface $key)
$keyset = clone $this;
$keyset->keys[] = $key;
return $keyset;
public function removeKey($key)
if (isset($this->keys[$key])) {
unset($keyset->keys[$key]);
return $this;
public function jsonSerialize()
return ['keys' => array_values($this->getKeys())];
public function count($mode = COUNT_NORMAL)
return count($this->getKeys(), $mode);
public function current()
return isset($this->keys[$this->position]) ? $this->keys[$this->position] : null;
public function key()
return $this->position;
public function next()
$this->position++;
public function rewind()
$this->position = 0;
public function valid()
return $this->current() instanceof JWKInterface;
public function countKeys()
return count($this->keys);