Completed
Push — master ( b6ba4a...f73367 )
by Florent
02:26
created

JWTLoaderSource::getNodeDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 22
nc 1
nop 1
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\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class JWTLoaderSource implements SourceInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getName()
25
    {
26
        return 'jwt_loaders';
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function createService($name, array $config, ContainerBuilder $container)
33
    {
34
        $service_id = sprintf('jose.jwt_loader.%s', $name);
35
        $definition = new Definition('Jose\JWTLoader');
36
        $definition->setFactory([
37
            new Reference('jose.factory.service'),
38
            'createJWTLoader',
39
        ]);
40
        $definition->setArguments([
41
            new Reference($config['checker']),
42
            new Reference($config['verifier']),
43
            null === $config['decrypter'] ? null : new Reference($config['decrypter']),
44
            null === $config['logger'] ? null : new Reference($config['logger']),
45
        ]);
46
47
        $container->setDefinition($service_id, $definition);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getNodeDefinition(ArrayNodeDefinition $node)
54
    {
55
        $node->children()
56
                ->arrayNode($this->getName())
57
                    ->useAttributeAsKey('name')
58
                    ->prototype('array')
59
                        ->children()
60
                            ->scalarNode('verifier')
61
                                ->isRequired()
62
                            ->end()
63
                            ->scalarNode('checker')
64
                                ->isRequired()
65
                            ->end()
66
                            ->scalarNode('decrypter')
67
                                ->defaultNull()
68
                            ->end()
69
                            ->scalarNode('logger')
70
                                ->defaultNull()
71
                            ->end()
72
                        ->end()
73
                    ->end()
74
                ->end()
75
            ->end();
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function prepend(ContainerBuilder $container, array $config)
82
    {
83
    }
84
}
85