Failed Conditions
Push — master ( c4fa4a...5cc583 )
by Florent
02:12
created

JKUSource::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
41
        $loader->load('jku_source.yml');
42
        $this->createService($configs[$this->name()], $container);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    private function createService(array $config, ContainerBuilder $container)
49
    {
50
        $container->setAlias('jose.http_client', $config['client']);
51
        $container->setAlias('jose.request_factory', $config['request_factory']);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getNodeDefinition(ArrayNodeDefinition $node)
58
    {
59
        $node
60
            ->children()
61
                ->arrayNode('jku_factory')
62
                    ->canBeEnabled()
63
                    ->children()
64
                        ->scalarNode('client')
65
                            ->info('HTTP Client used to retrieve key sets.')
66
                            ->isRequired()
67
                            ->defaultNull()
68
                        ->end()
69
                        ->scalarNode('request_factory')
70
                            ->defaultValue('Http\Message\MessageFactory\GuzzleMessageFactory')
71
                        ->end()
72
                    ->end()
73
                ->end()
74
            ->end();
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function prepend(ContainerBuilder $container, array $config): ?array
81
    {
82
        return null;
83
    }
84
}
85