Completed
Push — master ( 755e9e...9e5cc9 )
by Florent
01:58
created

CheckerSource::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 3
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\DependencyInjection\Source;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\DependencyInjection\Definition;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class CheckerSource implements SourceInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getName()
25
    {
26
        return 'checkers';
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function createService($name, array $config, ContainerBuilder $container)
33
    {
34
        $service_id = sprintf('jose.checker.%s', $name);
35
        $definition = new Definition('Jose\Checker\CheckerManager');
36
        $definition->setFactory([
37
            new Reference('jose.factory.service'),
38
            'createChecker',
39
        ]);
40
        $definition->setArguments([
41
            $config['claims'],
42
            $config['headers'],
43
        ]);
44
45
        $container->setDefinition($service_id, $definition);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function addConfigurationSection(ArrayNodeDefinition $node)
52
    {
53
        $node->children()
54
            ->arrayNode('checkers')
55
            ->useAttributeAsKey('name')
56
            ->prototype('array')
57
            ->children()
58
            ->arrayNode('claims')->isRequired()->prototype('scalar')->end()->end()
59
            ->arrayNode('headers')->isRequired()->prototype('scalar')->end()->end()
60
            ->end()
61
            ->end()
62
            ->end()
63
            ->end();
64
    }
65
}
66