Failed Conditions
Push — master ( 80e3c6...e90bf3 )
by Florent
01:55
created

JKUSource::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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\KeyManagement\DependencyInjection\Source;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceInterface;
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 SourceInterface
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
                            ->defaultValue('Http\Message\MessageFactory\GuzzleMessageFactory')
66
                        ->end()
67
                    ->end()
68
                ->end()
69
            ->end();
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function prepend(ContainerBuilder $container, array $config): ?array
76
    {
77
        return null;
78
    }
79
}
80