Completed
Pull Request — master (#24)
by Florent
02:31
created

Keys::createDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 6
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\JWKSetSource;
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
class Keys extends AbstractSource implements JWKSetSourceInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function createDefinition(ContainerBuilder $container, array $config)
26
    {
27
        $definition = new Definition('Jose\Object\JWKSet');
28
        foreach ($config['id'] as $key_id) {
29
            $ref = new Reference($key_id);
30
            $definition->addMethodCall('addKey', [$ref]);
31
        }
32
33
        return $definition;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getKeySet()
40
    {
41
        return 'keys';
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function addConfiguration(NodeDefinition $node)
48
    {
49
        parent::addConfiguration($node);
50
        $node
51
            ->children()
52
                ->arrayNode('id')
53
                    ->prototype('scalar')
54
                    ->end()
55
                    ->isRequired()
56
                ->end()
57
            ->end();
58
    }
59
}
60