Completed
Push — master ( f67525...5cf1da )
by Florent
02:34
created

JWKSetManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
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
use Jose\Finder\JWKSetFinderInterface;
16
17
/**
18
 */
19
class JWKSetManager implements JWKSetManagerInterface
20
{
21
    use HasJWKManager;
22
23
    /**
24
     * JWKSetManager constructor.
25
     *
26
     * @param \Jose\JWKManagerInterface $jwk_manager
27
     */
28
    public function __construct(JWKManagerInterface $jwk_manager)
29
    {
30
        $this->setJWKManager($jwk_manager);
31
    }
32
33
    /**
34
     * @var \Jose\Finder\JWKSetFinderInterface[]
35
     */
36
    private $finders = [];
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function addJWKSetFinder(JWKSetFinderInterface $finder)
42
    {
43
        $this->finders[] = $finder;
44
45
        return $this;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function findJWKSet(array $header)
52
    {
53
        foreach ($this->finders as $finder) {
54
            $result = $finder->findJWKSet($header);
55
            if (is_array($result)) {
56
                return $this->createJWKSet($result);
57
            }
58
        }
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function createJWKSet(array $values = [])
65
    {
66
        $key_set = new JWKSet();
67
        if (array_key_exists('keys', $values)) {
68
            foreach ($values['keys'] as $value) {
69
                $key = $this->getJWKManager()->createJWK($value);
70
                $key_set->addKey($key);
71
            }
72
        }
73
74
        return $key_set;
75
    }
76
}
77