JWKUriSource   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 16 3
A getNodeDefinition() 0 34 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-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;
15
16
use Jose\Bundle\JoseFramework\Controller\JWKSetController;
17
use Jose\Bundle\JoseFramework\Controller\JWKSetControllerFactory;
18
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
19
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Definition;
22
use Symfony\Component\DependencyInjection\Reference;
23
24
class JWKUriSource implements Source
25
{
26
    public function name(): string
27
    {
28
        return 'jwk_uris';
29
    }
30
31
    public function load(array $configs, ContainerBuilder $container): void
32
    {
33
        foreach ($configs[$this->name()] as $name => $itemConfig) {
34
            $service_id = sprintf('jose.controller.%s', $name);
35
            $definition = new Definition(JWKSetController::class);
36
            $definition->setFactory([new Reference(JWKSetControllerFactory::class), 'create']);
37
            $definition->setArguments([new Reference($itemConfig['id'])]);
38
            $definition->addTag('jose.jwk_uri.controller', ['path' => $itemConfig['path']]);
39
            $definition->addTag('controller.service_arguments');
40
            $definition->setPublic($itemConfig['is_public']);
41
            foreach ($itemConfig['tags'] as $id => $attributes) {
42
                $definition->addTag($id, $attributes);
43
            }
44
            $container->setDefinition($service_id, $definition);
45
        }
46
    }
47
48
    public function getNodeDefinition(NodeDefinition $node): void
49
    {
50
        $node->children()
51
            ->arrayNode('jwk_uris')
52
            ->treatFalseLike([])
53
            ->treatNullLike([])
54
            ->useAttributeAsKey('name')
55
            ->arrayPrototype()
56
            ->children()
57
            ->scalarNode('id')
58
            ->info('The service ID of the Key Set to share.')
59
            ->isRequired()
60
            ->end()
61
            ->scalarNode('path')
62
            ->info('To share the JWKSet, then set a valid path (e.g. "/jwkset.json").')
63
            ->isRequired()
64
            ->end()
65
            ->arrayNode('tags')
66
            ->info('A list of tags to be associated to the service.')
67
            ->useAttributeAsKey('name')
68
            ->treatNullLike([])
69
            ->treatFalseLike([])
70
            ->variablePrototype()->end()
71
            ->end()
72
            ->booleanNode('is_public')
73
            ->info('If true, the service will be public, else private.')
74
            ->defaultTrue()
75
            ->end()
76
            ->end()
77
            ->end()
78
            ->end()
79
            ->end()
80
        ;
81
    }
82
83
    public function prepend(ContainerBuilder $container, array $config): array
84
    {
85
        return [];
86
    }
87
}
88