Failed Conditions
Push — master ( df44e5...b25e13 )
by Florent
02:17
created

JWSLoader::getNodeDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 35
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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\Signature;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
17
use Jose\Component\Signature\JWSLoaderFactory;
18
use Jose\Component\Signature\JWSLoader as JWSLoaderService;
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 JWSLoader.
26
 */
27
final class JWSLoader implements Source
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function name(): string
33
    {
34
        return 'loaders';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function load(array $configs, ContainerBuilder $container)
41
    {
42
        foreach ($configs[$this->name()] as $name => $itemConfig) {
43
            $service_id = sprintf('jose.jws_loader.%s', $name);
44
            $definition = new Definition(JWSLoaderService::class);
45
            $definition
46
                ->setFactory([new Reference(JWSLoaderFactory::class), 'create'])
47
                ->setArguments([
48
                    $itemConfig['serializers'],
49
                    $itemConfig['signature_algorithms'],
50
                    $itemConfig['header_checkers'],
51
                ])
52
                ->addTag('jose.jws_loader')
53
                ->setPublic($itemConfig['is_public']);
54
55
            $container->setDefinition($service_id, $definition);
56
        }
57
    }
58
59
    public function getNodeDefinition(ArrayNodeDefinition $node)
60
    {
61
        $node
62
            ->children()
63
                ->arrayNode($this->name())
64
                    ->requiresAtLeastOneElement()
65
                    ->useAttributeAsKey('name')
66
                    ->prototype('array')
67
                        ->children()
68
                            ->booleanNode('is_public')
69
                                ->info('If true, the service will be public, else private.')
70
                                ->defaultTrue()
71
                            ->end()
72
                            ->arrayNode('signature_algorithms')
73
                                ->info('A list of signature algorithm aliases.')
74
                                ->useAttributeAsKey('name')
75
                                ->isRequired()
76
                                ->prototype('scalar')->end()
77
                            ->end()
78
                            ->arrayNode('serializers')
79
                                ->info('A list of signature serializer aliases.')
80
                                ->useAttributeAsKey('name')
81
                                ->requiresAtLeastOneElement()
82
                                ->prototype('scalar')->end()
83
                            ->end()
84
                            ->arrayNode('header_checkers')
85
                                ->info('A list of header checker aliases.')
86
                                ->useAttributeAsKey('name')
87
                                ->treatNullLike([])
88
                                ->treatFalseLike([])
89
                                ->prototype('scalar')->end()
90
                            ->end()
91
                        ->end()
92
                    ->end()
93
                ->end()
94
            ->end();
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function prepend(ContainerBuilder $container, array $config): array
101
    {
102
        return [];
103
    }
104
}
105