NestedTokenLoader::name()   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\NestedToken;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
17
use Jose\Bundle\JoseFramework\Services\NestedTokenLoaderFactory;
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 NestedTokenLoader implements Source
24
{
25
    public function name(): string
26
    {
27
        return 'loaders';
28
    }
29
30
    public function load(array $configs, ContainerBuilder $container): void
31
    {
32
        foreach ($configs[$this->name()] as $name => $itemConfig) {
33
            $service_id = sprintf('jose.nested_token_loader.%s', $name);
34
            $definition = new Definition(self::class);
35
            $definition
36
                ->setFactory([new Reference(NestedTokenLoaderFactory::class), 'create'])
37
                ->setArguments([
38
                    $itemConfig['jwe_serializers'],
39
                    $itemConfig['key_encryption_algorithms'],
40
                    $itemConfig['content_encryption_algorithms'],
41
                    $itemConfig['compression_methods'],
42
                    $itemConfig['jwe_header_checkers'],
43
                    $itemConfig['jws_serializers'],
44
                    $itemConfig['signature_algorithms'],
45
                    $itemConfig['jws_header_checkers'],
46
                ])
47
                ->addTag('jose.nested_token_loader')
48
                ->setPublic($itemConfig['is_public'])
49
            ;
50
            foreach ($itemConfig['tags'] as $id => $attributes) {
51
                $definition->addTag($id, $attributes);
52
            }
53
            $container->setDefinition($service_id, $definition);
54
        }
55
    }
56
57
    public function getNodeDefinition(NodeDefinition $node): void
58
    {
59
        $node->children()
60
            ->arrayNode($this->name())
61
            ->treatNullLike([])
62
            ->treatFalseLike([])
63
            ->useAttributeAsKey('name')
64
            ->arrayPrototype()
65
            ->children()
66
            ->booleanNode('is_public')
67
            ->info('If true, the service will be public, else private.')
68
            ->defaultTrue()
69
            ->end()
70
            ->arrayNode('signature_algorithms')
71
            ->info('A list of signature algorithm aliases.')
72
            ->useAttributeAsKey('name')
73
            ->isRequired()
74
            ->scalarPrototype()->end()
75
            ->end()
76
            ->arrayNode('key_encryption_algorithms')
77
            ->info('A list of key encryption algorithm aliases.')
78
            ->useAttributeAsKey('name')
79
            ->isRequired()
80
            ->scalarPrototype()->end()
81
            ->end()
82
            ->arrayNode('content_encryption_algorithms')
83
            ->info('A list of key encryption algorithm aliases.')
84
            ->useAttributeAsKey('name')
85
            ->isRequired()
86
            ->scalarPrototype()->end()
87
            ->end()
88
            ->arrayNode('compression_methods')
89
            ->info('A list of compression method aliases.')
90
            ->useAttributeAsKey('name')
91
            ->defaultValue(['DEF'])
92
            ->scalarPrototype()->end()
93
            ->end()
94
            ->arrayNode('jws_serializers')
95
            ->info('A list of JWS serializer aliases.')
96
            ->useAttributeAsKey('name')
97
            ->treatNullLike([])
98
            ->treatFalseLike([])
99
            ->isRequired()
100
            ->requiresAtLeastOneElement()
101
            ->scalarPrototype()->end()
102
            ->end()
103
            ->arrayNode('jwe_serializers')
104
            ->info('A list of JWE serializer aliases.')
105
            ->useAttributeAsKey('name')
106
            ->treatNullLike([])
107
            ->treatFalseLike([])
108
            ->isRequired()
109
            ->requiresAtLeastOneElement()
110
            ->scalarPrototype()->end()
111
            ->end()
112
            ->arrayNode('jws_header_checkers')
113
            ->info('A list of header checker aliases.')
114
            ->useAttributeAsKey('name')
115
            ->treatNullLike([])
116
            ->treatFalseLike([])
117
            ->scalarPrototype()->end()
118
            ->end()
119
            ->arrayNode('jwe_header_checkers')
120
            ->info('A list of header checker aliases.')
121
            ->useAttributeAsKey('name')
122
            ->treatNullLike([])
123
            ->treatFalseLike([])
124
            ->scalarPrototype()->end()
125
            ->end()
126
            ->arrayNode('tags')
127
            ->info('A list of tags to be associated to the service.')
128
            ->useAttributeAsKey('name')
129
            ->treatNullLike([])
130
            ->treatFalseLike([])
131
            ->variablePrototype()->end()
132
            ->end()
133
            ->end()
134
            ->end()
135
            ->end()
136
        ;
137
    }
138
139
    public function prepend(ContainerBuilder $container, array $config): array
140
    {
141
        return [];
142
    }
143
}
144