Completed
Pull Request — master (#24)
by Florent
02:31
created

AbstractSource   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
createDefinition() 0 1 ?
A create() 0 6 1
A addConfiguration() 0 10 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\NodeDefinition;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
abstract class AbstractSource
18
{
19
    /**
20
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
21
     * @param array                                                   $config
22
     *
23
     * @return \Symfony\Component\DependencyInjection\Definition
24
     */
25
    abstract protected function createDefinition(ContainerBuilder $container, array $config);
26
27
    /**
28
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
29
     * @param string                                                  $id
30
     * @param array                                                   $config
31
     */
32
    public function create(ContainerBuilder $container, $id, array $config)
33
    {
34
        $definition = $this->createDefinition($container, $config);
35
        $definition->setPublic($config['is_public']);
36
        $container->setDefinition($id, $definition);
37
    }
38
39
    /**
40
     * @param \Symfony\Component\Config\Definition\Builder\NodeDefinition $node
41
     */
42
    public function addConfiguration(NodeDefinition $node)
43
    {
44
        $node
45
            ->children()
46
                ->booleanNode('is_public')
47
                    ->info('If true, the service will be public, else private.')
48
                    ->defaultTrue()
49
                ->end()
50
            ->end();
51
    }
52
}
53