Completed
Pull Request — develop (#273)
by Samuel
23:34 queued 09:33
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 23
ccs 18
cts 18
cp 1
rs 9.0857
c 1
b 1
f 0
cc 1
eloc 19
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Configuration definition to be able to define every swagger source via /app/config/config.yml
4
 */
5
6
namespace Graviton\ProxyBundle\DependencyInjection;
7
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
11
/**
12
 * Class Configuration
13
 *
14
 * To learn more see {@link http://scm.to/00Yb}
15
 *
16
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18
 * @link    http://swisscom.ch
19
 */
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * Defines the structure of the configuration information.
24
     *
25
     * Example structure to be used in /app/config/config.yml:
26
     *
27
     *   graviton_proxy:
28
     *     sources:
29
     *       swagger:
30
     *         petstore:
31
     *           prefix: petstore
32
     *           uri:    http://petstore.swagger.io/v2/swagger.json
33
     *         another_source:
34
     *           prefix: myswaggerinstance
35
     *           uri:    http://swagger.example.org/swagger.json
36
     *
37
     * @return TreeBuilder
38
     */
39 1
    public function getConfigTreeBuilder()
40
    {
41 1
        $treeBuilder = new TreeBuilder();
42 1
        $rootNode = $treeBuilder->root('graviton_proxy');
43
44
        $rootNode
45 1
            ->children()
46 1
            ->arrayNode('sources')
47 1
            ->useAttributeAsKey('name')
48 1
            ->prototype('array')
49 1
            ->useAttributeAsKey('name')
50 1
            ->prototype('array')
51 1
            ->children()
52 1
            ->scalarNode('prefix')->isRequired()->cannotBeEmpty()->end()
53 1
            ->scalarNode('uri')->isRequired()->cannotBeEmpty()->end()
54 1
            ->end()
55 1
            ->end()
56 1
            ->end()
57 1
            ->end() // swagger_proxy
58 1
            ->end();
59
60 1
        return $treeBuilder;
61
    }
62
}
63