JWSBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A createService() 0 11 1
A getNodeDefinition() 0 22 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\JWSBuilderFactory;
18
use Jose\Component\Signature\JWSBuilder as JWSBuilderService;
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 JWSBuilder.
26
 */
27
final class JWSBuilder implements SourceInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function name(): string
33
    {
34
        return 'jws_builders';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function createService(string $name, array $config, ContainerBuilder $container)
41
    {
42
        $service_id = sprintf('jose.jws_builder.%s', $name);
43
        $definition = new Definition(JWSBuilderService::class);
44
        $definition
45
            ->setFactory([new Reference(JWSBuilderFactory::class), 'create'])
46
            ->setArguments([$config['signature_algorithms']])
47
            ->setPublic($config['is_public']);
48
49
        $container->setDefinition($service_id, $definition);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getNodeDefinition(ArrayNodeDefinition $node)
56
    {
57
        $node
58
            ->children()
59
                ->arrayNode($this->name())
60
                    ->useAttributeAsKey('name')
61
                    ->prototype('array')
62
                        ->children()
63
                            ->booleanNode('is_public')
64
                                ->info('If true, the service will be public, else private.')
65
                                ->defaultTrue()
66
                            ->end()
67
                            ->arrayNode('signature_algorithms')
68
                                ->useAttributeAsKey('name')
69
                                ->isRequired()
70
                                ->prototype('scalar')->end()
71
                            ->end()
72
                        ->end()
73
                    ->end()
74
                ->end()
75
            ->end();
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function prepend(ContainerBuilder $container, array $config): ?array
82
    {
83
        return null;
84
    }
85
}
86