Failed Conditions
Pull Request — master (#47)
by Florent
06:42
created

JWKSet::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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 Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\JWKSource;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource;
17
use Jose\Component\KeyManagement\JWKFactory;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Reference;
22
23
/**
24
 * Class JWKSet.
25
 */
26
final class JWKSet extends AbstractSource implements JWKSource
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function createDefinition(ContainerBuilder $container, array $config): Definition
32
    {
33
        $definition = new Definition(JWK::class);
34
        $definition->setFactory([
35
            new Reference(JWKFactory::class),
36
            'createFromKeySet',
37
        ]);
38
        $definition->setArguments([new Reference($config['key_set']), $config['index']]);
39
        $definition->addTag('jose.jwk');
40
41
        return $definition;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getKey(): string
48
    {
49
        return 'jwkset';
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function addConfiguration(NodeDefinition $node)
56
    {
57
        parent::addConfiguration($node);
58
        $node
59
            ->children()
60
                ->scalarNode('key_set')
61
                    ->info('The key set service.')
62
                    ->isRequired()->end()
63
                ->integerNode('index')
64
                    ->info('The index of the key in the key set.')
65
                    ->isRequired()
66
                ->end()
67
            ->end();
68
    }
69
}
70