Completed
Push — master ( de1564...663938 )
by Florent
10:19
created

RandomKey::generateKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 9
nc 2
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
abstract class RandomKey implements JWKSourceInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function create(ContainerBuilder $container, $id, array $config)
25
    {
26
        $definition = new Definition('Jose\Object\RotatableJWK');
27
        $definition->setFactory([
28
            new Reference('jose.factory.jwk'),
29
            'createRotatableKey',
30
        ]);
31
32
        $key_config = $this->getKeyConfig($config);
33
34
        $definition->setArguments([$config['storage_path'], $key_config, $config['ttl']]);
35
        $container->setDefinition($id, $definition);
36
    }
37
38
    /**
39
     * @param array $config
40
     *
41
     * @return array
42
     */
43
    abstract protected function getKeyConfig(array $config);
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function addConfiguration(NodeDefinition $node)
49
    {
50
        $node
51
            ->children()
52
                ->scalarNode('storage_path')->isRequired()->end()
53
                ->integerNode('ttl')->defaultValue(0)->min(0)->end()
54
                ->arrayNode('additional_values')
55
                    ->defaultValue([])
56
                    ->useAttributeAsKey('key')
57
                    ->prototype('variable')->end()
58
                ->end()
59
            ->end();
60
    }
61
}
62