Completed
Push — master ( 8db99d...40ab14 )
by Florent
14:30 queued 11:57
created

JWKSetManager::addJWKSetFinder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 6
rs 9.4286
c 1
b 1
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose;
13
14
use Jose\Behaviour\HasJWKManager;
15
16
use Jose\Finder\JWKSetFinderInterface;
17
18
/**
19
 */
20
class JWKSetManager implements JWKSetManagerInterface
21
{
22
    use HasJWKManager;
23
24
    /**
25
     * @var \Jose\Finder\JWKSetFinderInterface[]
26
     */
27
    private $finders = [];
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function addJWKSetFinder(JWKSetFinderInterface $finder)
33
    {
34
        $this->finders[] = $finder;
35
36
        return $this;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function findJWKSet(array $header)
43
    {
44
        foreach ($this->finders as $finder) {
45
            $result = $finder->findJWKSet($header);
46
            if (is_array($result)) {
47
                return $this->createJWKSet($result);
48
            }
49
        }
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function createJWKSet(array $values = [])
56
    {
57
        $key_set = new JWKSet();
58
        if (array_key_exists('keys', $values)) {
59
            foreach ($values['keys'] as $value) {
60
                $key = $this->getJWKManager()->createJWK($value);
61
                $key_set->addKey($key);
62
            }
63
        }
64
65
        return $key_set;
66
    }
67
}
68