JWTCreatorSource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A createService() 0 16 2
A getNodeDefinition() 0 18 1
A prepend() 0 3 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 JWTCreatorSource implements SourceInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getName()
25
    {
26
        return 'jwt_creators';
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function createService($name, array $config, ContainerBuilder $container)
33
    {
34
        $service_id = sprintf('jose.jwt_creator.%s', $name);
35
        $definition = new Definition('Jose\JWTCreator');
36
        $definition->setFactory([
37
            new Reference('jose.factory.service'),
38
            'createJWTCreator',
39
        ]);
40
        $definition->setArguments([
41
            new Reference($config['signer']),
42
            null === $config['encrypter'] ? null : new Reference($config['encrypter']),
43
        ]);
44
        $definition->setPublic($config['is_public']);
45
46
        $container->setDefinition($service_id, $definition);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getNodeDefinition(ArrayNodeDefinition $node)
53
    {
54
        $node->children()
55
                ->arrayNode($this->getName())
56
                    ->useAttributeAsKey('name')
57
                    ->prototype('array')
58
                        ->children()
59
                            ->booleanNode('is_public')
60
                                ->info('If true, the service will be public, else private.')
61
                                ->defaultTrue()
62
                            ->end()
63
                            ->scalarNode('signer')->isRequired()->end()
64
                            ->scalarNode('encrypter')->defaultNull()->end()
65
                        ->end()
66
                    ->end()
67
                ->end()
68
            ->end();
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function prepend(ContainerBuilder $container, array $config)
75
    {
76
    }
77
}
78