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

KeyFile::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A KeyFile::createDefinition() 0 15 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 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 KeyFile 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
            'createFromKeyFile',
31
        ]);
32
        $definition->setArguments([
33
            $config['path'],
34
            $config['password'],
35
            $config['additional_values'],
36
        ]);
37
38
        return $definition;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getKey()
45
    {
46
        return 'file';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function addConfiguration(NodeDefinition $node)
53
    {
54
        parent::addConfiguration($node);
55
        $node
56
            ->children()
57
                ->scalarNode('path')->isRequired()->end()
58
                ->scalarNode('password')->defaultNull()->end()
59
                ->arrayNode('additional_values')
60
                    ->defaultValue([])
61
                    ->useAttributeAsKey('key')
62
                    ->prototype('variable')->end()
63
                ->end()
64
            ->end();
65
    }
66
}
67