Completed
Pull Request — master (#8)
by
unknown
03:19
created

Configuration::loadConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Mediapart Selligent Client API
5
 *
6
 * CC BY-NC-SA <https://github.com/mediapart/selligent>
7
 *
8
 * For the full license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mediapart\Selligent;
13
14
use Symfony\Component\Config\Definition\ConfigurationInterface;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Yaml\Yaml;
17
use Symfony\Component\Config\Definition\Processor;
18
19
20
/**
21
 * Class Configuration
22
 * @package Mediapart\Selligent
23
 */
24
class Configuration implements ConfigurationInterface
25
{
26
    /**
27
     * Define configTree
28
     * @return TreeBuilder
29
     */
30
    public function getConfigTreeBuilder()
31
    {
32
        $treeBuilder = new TreeBuilder();
33
        $rootNode = $treeBuilder->root('selligent');
34
35
        $rootNode
36
          ->children()
37
            ->scalarNode('login')
38
                ->isRequired()
39
                ->cannotBeEmpty()
40
            ->end()
41
            ->scalarNode('password')
42
              ->isRequired()
43
              ->cannotBeEmpty()
44
            ->end()
45
            ->scalarNode('namespace')
46
                ->defaultValue('http://tempuri.org/')
47
            ->end()
48
            ->scalarNode('wsdl')
49
              ->isRequired()
50
              ->cannotBeEmpty()
51
            ->end()
52
            ->scalarNode('list')
53
                ->isRequired()
54
            ->end()
55
            ->arrayNode('options')
56
                ->children()
57
                    ->arrayNode('classmap')
58
                        ->isRequired()
59
                        ->prototype('scalar')
60
                    ->end()
61
                ->end()
62
            ->end()
63
          ->end()
64
        ;
65
66
        return $treeBuilder;
67
    }
68
69
    /**
70
     * load, validate and return configuration
71
     * @param string $configFile
72
     * @return array
73
     */
74
    public function loadConfig($configFile)
75
    {
76
        $config = Yaml::parse($configFile);
77
        $processor = new Processor();
78
79
        $processedConfiguration = $processor->processConfiguration(
80
          new Configuration(),
81
          $config
82
        );
83
        return $processedConfiguration;
84
    }
85
}
86