Failed Conditions
Pull Request — master (#74)
by Florent
03:06 queued 57s
created

HeaderChecker::getNodeDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 21
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\Checker;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
17
use Jose\Component\Checker\HeaderCheckerManagerFactory;
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 HeaderChecker.
26
 */
27
final class HeaderChecker implements Source
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function name(): string
33
    {
34
        return 'headers';
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.header_checker.%s', $name);
44
            $definition = new Definition(JWSVerifierService::class);
45
            $definition
46
                ->setFactory([new Reference(HeaderCheckerManagerFactory::class), 'create'])
47
                ->setArguments([
48
                    $itemConfig['headers'],
49
                ])
50
                ->addTag('jose.header_checker_manager')
51
                ->setPublic($itemConfig['is_public']);
52
            $container->setDefinition($service_id, $definition);
53
        }
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getNodeDefinition(ArrayNodeDefinition $node)
60
    {
61
        $node
62
            ->children()
63
                ->arrayNode($this->name())
64
                    ->useAttributeAsKey('name')
65
                    ->prototype('array')
66
                        ->children()
67
                            ->booleanNode('is_public')
68
                                ->info('If true, the service will be public, else private.')
69
                                ->defaultTrue()
70
                            ->end()
71
                            ->arrayNode('headers')
72
                                ->info('A list of header aliases to be set in the claim checker.')
73
                                ->useAttributeAsKey('name')
74
                                ->isRequired()
75
                                ->prototype('scalar')->end()
76
                            ->end()
77
                        ->end()
78
                    ->end()
79
                ->end()
80
            ->end();
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function prepend(ContainerBuilder $container, array $config): array
87
    {
88
        return [];
89
    }
90
}
91