Completed
Pull Request — master (#24)
by Florent
06:28 queued 03:25
created

JWKSet::addConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 1
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 Symfony\Component\Config\Definition\Builder\NodeDefinition;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
class JWKSet implements JWKSourceInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function create(ContainerBuilder $container, $id, array $config)
25
    {
26
        $definition = new Definition('Jose\Object\JWK');
27
        $definition->setFactory([
28
            new Reference('jose.factory.jwk'),
29
            'createFromKeySet',
30
        ]);
31
        $definition->setArguments([$config['key_set'], $config['key_index']]);
32
        $definition->setPublic($config['is_public']);
33
34
        $container->setDefinition($id, $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
        $node
51
            ->children()
52
                ->booleanNode('is_public')
53
                    ->info('If true, the service will be public, else private.')
54
                    ->defaultTrue()
55
                ->end()
56
                ->scalarNode('key_set')
57
                    ->info('The key set service.')
58
                    ->isRequired()->end()
59
                ->integerNode('key_index')
60
                    ->info('The index of the key in the key set.')
61
                    ->isRequired()
62
                ->end()
63
            ->end();
64
    }
65
}
66