Failed Conditions
Pull Request — master (#47)
by Florent
06:42
created

JKUSource::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\JoseFramework\DependencyInjection\Source\KeyManagement;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\Config\FileLocator;
21
22
/**
23
 * Class JKUSource.
24
 */
25
final class JKUSource implements Source
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function name(): string
31
    {
32
        return 'jku_factory';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function load(array $configs, ContainerBuilder $container)
39
    {
40
        if (true === $configs[$this->name()]['enabled']) {
41
            $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
42
            $loader->load('jku_source.yml');
43
            $loader->load('jku_commands.yml');
44
            $container->setAlias('jose.http_client', $configs[$this->name()]['client']);
45
            $container->setAlias('jose.request_factory', $configs[$this->name()]['request_factory']);
46
        }
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getNodeDefinition(ArrayNodeDefinition $node)
53
    {
54
        $node
55
            ->children()
56
                ->arrayNode('jku_factory')
57
                    ->canBeEnabled()
58
                    ->children()
59
                        ->scalarNode('client')
60
                            ->info('HTTP Client used to retrieve key sets.')
61
                            ->isRequired()
62
                            ->defaultNull()
63
                        ->end()
64
                        ->scalarNode('request_factory')
65
                            ->info('The request factory service.')
66
                            ->isRequired()
67
                        ->end()
68
                    ->end()
69
                ->end()
70
            ->end();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function prepend(ContainerBuilder $container, array $config): array
77
    {
78
        return [];
79
    }
80
}
81