CertificateFile::getKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\JWKSource;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource;
17
use Jose\Component\KeyManagement\JWKFactory;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Reference;
22
23
class CertificateFile extends AbstractSource implements JWKSource
24
{
25
    public function createDefinition(ContainerBuilder $container, array $config): Definition
26
    {
27
        $definition = new Definition(\Jose\Component\Core\JWK::class);
28
        $definition->setFactory([
29
            new Reference(JWKFactory::class),
30
            'createFromCertificateFile',
31
        ]);
32
        $definition->setArguments([
33
            $config['path'],
34
            $config['additional_values'],
35
        ]);
36
        $definition->addTag('jose.jwk');
37
38
        return $definition;
39
    }
40
41
    public function getKey(): string
42
    {
43
        return 'certificate';
44
    }
45
46
    public function addConfiguration(NodeDefinition $node): void
47
    {
48
        parent::addConfiguration($node);
49
        $node
50
            ->children()
51
            ->scalarNode('path')
52
            ->info('Path of the certificate file.')
53
            ->isRequired()
54
            ->end()
55
            ->arrayNode('additional_values')
56
            ->info('Additional values to be added to the key.')
57
            ->defaultValue([])
58
            ->useAttributeAsKey('key')
59
            ->variablePrototype()->end()
60
            ->end()
61
            ->end()
62
        ;
63
    }
64
}
65