Failed Conditions
Push — master ( 5537f8...d96005 )
by Florent
02:00
created

JWSVerifier   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 83
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 4 1
A createService() 0 17 2
B getNodeDefinition() 0 32 1
A prepend() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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\Signature\DependencyInjection\Source;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceInterface;
17
use Jose\Component\Signature\JWSVerifierFactory;
18
use Jose\Component\Signature\JWSVerifier as JWSVerifierService;
19
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Definition;
22
use Symfony\Component\DependencyInjection\Reference;
23
24
/**
25
 * Class JWSVerifier.
26
 */
27
final class JWSVerifier implements SourceInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function name(): string
33
    {
34
        return 'jws_verifiers';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function load(array $configs, ContainerBuilder $container)
41
    {
42
        $this->createService($configs[$this->name()], $container);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    private function createService(array $config, ContainerBuilder $container)
49
    {
50
        foreach ($config as $name => $itemConfig) {
51
            $service_id = sprintf('jose.jws_verifier.%s', $name);
52
            $definition = new Definition(JWSVerifierService::class);
53
            $definition
54
                ->setFactory([new Reference(JWSVerifierFactory::class), 'create'])
55
                ->setArguments([
56
                    $itemConfig['signature_algorithms'],
57
                    $itemConfig['header_checkers'],
58
                    $itemConfig['serializers'],
59
                ])
60
                ->setPublic($itemConfig['is_public']);
61
62
            $container->setDefinition($service_id, $definition);
63
        }
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getNodeDefinition(ArrayNodeDefinition $node)
70
    {
71
        $node
72
            ->children()
73
                ->arrayNode($this->name())
74
                    ->useAttributeAsKey('name')
75
                    ->prototype('array')
76
                        ->children()
77
                            ->booleanNode('is_public')
78
                                ->info('If true, the service will be public, else private.')
79
                                ->defaultTrue()
80
                            ->end()
81
                            ->arrayNode('signature_algorithms')
82
                                ->useAttributeAsKey('name')
83
                                ->isRequired()
84
                                ->prototype('scalar')->end()
85
                            ->end()
86
                            ->arrayNode('header_checkers')
87
                                ->useAttributeAsKey('name')
88
                                ->isRequired()
89
                                ->prototype('scalar')->end()
90
                            ->end()
91
                            ->arrayNode('serializers')
92
                                ->useAttributeAsKey('name')
93
                                ->treatNullLike(['jws_compact'])
94
                                ->prototype('scalar')->end()
95
                            ->end()
96
                        ->end()
97
                    ->end()
98
                ->end()
99
            ->end();
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function prepend(ContainerBuilder $container, array $config): ?array
106
    {
107
        return null;
108
    }
109
}
110