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

CertificateFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

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