Failed Conditions
Push — v7 ( 8da077...12d27f )
by Florent
02:14
created

ClaimChecker::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 3
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\Checker\DependencyInjection\Source;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceInterface;
17
use Jose\Component\Checker\ClaimCheckerManagerFactory;
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 ClaimChecker implements SourceInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function name(): string
33
    {
34
        return 'claim_checkers';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function createService(string $name, array $config, ContainerBuilder $container)
41
    {
42
        $service_id = sprintf('jose.claim_checker.%s', $name);
43
        $definition = new Definition(JWSLoaderService::class);
44
        $definition
45
            ->setFactory([new Reference(ClaimCheckerManagerFactory::class), 'create'])
46
            ->setArguments([
47
                $config['claims'],
48
            ])
49
            ->setPublic($config['is_public']);
50
51
        $container->setDefinition($service_id, $definition);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getNodeDefinition(ArrayNodeDefinition $node)
58
    {
59
        $node
60
            ->children()
61
                ->arrayNode($this->name())
62
                    ->useAttributeAsKey('name')
63
                    ->prototype('array')
64
                        ->children()
65
                            ->booleanNode('is_public')
66
                                ->info('If true, the service will be public, else private.')
67
                                ->defaultTrue()
68
                            ->end()
69
                            ->arrayNode('claims')
70
                                ->useAttributeAsKey('name')
71
                                ->isRequired()
72
                                ->prototype('scalar')->end()
73
                            ->end()
74
                        ->end()
75
                    ->end()
76
                ->end()
77
            ->end();
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function prepend(ContainerBuilder $container, array $config): ?array
84
    {
85
        return null;
86
    }
87
}
88