JWKSet::createDefinition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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