Configuration::addSoapSection()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 33
cp 0
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 31
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AMF\WebServicesClientBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
9
/**
10
 * This is the class that validates and merges configuration from your app/config files
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        $treeBuilder = new TreeBuilder();
22
        $rootNode = $treeBuilder->root('amf_web_services_client');
23
24
        // Here you should define the parameters that are allowed to
25
        // configure your bundle. See the documentation linked above for
26
        // more information on that topic.
27
        $this->addSoapSection($rootNode);
28
        $this->addRestSection($rootNode);
29
30
        return $treeBuilder;
31
    }
32
33
    /**
34
     * Adds the config of soap to global config.
35
     *
36
     * @param ArrayNodeDefinition $node The root element for the config nodes.
37
     *
38
     * @return void
39
     */
40
    protected function addSoapSection(ArrayNodeDefinition $node)
41
    {
42
        $node->children()
43
                ->arrayNode('soap')
44
                ->addDefaultsIfNotSet()
45
                ->children()
46
                    ->arrayNode('endpoints')
47
                    ->useAttributeAsKey('name')
48
                    ->prototype('array')
49
                        ->children()
50
                            ->scalarNode('class')->defaultNull()->isRequired()->cannotBeEmpty()->end()
51
                            ->scalarNode('wsdl')->defaultNull()->isRequired()->cannotBeEmpty()->end()
52
                            ->arrayNode('options')
53
                                ->addDefaultsIfNotSet()
54
                                ->children()
55
                                    ->booleanNode('trace')->defaultTrue()->end()
56
                                    ->booleanNode('exceptions')->defaultTrue()->end()
57
                                    ->scalarNode("encoding")->defaultValue("UTF-8")->end()
58
                                ->end()
59
                            ->end()
60
                            ->arrayNode('wsse')
61
                                ->addDefaultsIfNotSet()
62
                                ->canBeEnabled()
63
                                ->children()
64
                                    ->scalarNode('username')->defaultNull()->end()
65
                                    ->scalarNode('password')->defaultNull()->end()
66
                                ->end()
67
                            ->end()
68
                        ->end()
69
                    ->end()
70
                ->end()
71
            ->end();
72
    }
73
74
    /**
75
     * Adds the config of rest to global config.
76
     *
77
     * @param ArrayNodeDefinition $node The root node of the config for this bundle.
78
     *
79
     * @return void
80
     */
81
    private function addRestSection(ArrayNodeDefinition $node)
82
    {
83
        $schemes    = array('https', 'http');
84
        $delimiters = array('/', '?');
85
86
        $node->children()
87
                ->arrayNode('rest')
88
                ->addDefaultsIfNotSet()
89
                ->children()
90
                    ->arrayNode('decoders')
91
                        ->useAttributeAsKey('name')
92
                        ->defaultValue(array('json' => 'amf_web_services_client.rest.decoder.json', 'xml' => 'amf_web_services_client.rest.decoder.xml'))
93
                        ->prototype('scalar')->end()
94
                    ->end()
95
                    ->arrayNode('encoders')
96
                        ->useAttributeAsKey('name')
97
                        ->defaultValue(array('json' => 'amf_web_services_client.rest.encoder.json', 'xml' => 'amf_web_services_client.rest.encoder.xml'))
98
                        ->prototype('scalar')->end()
99
                    ->end()
100
                    ->arrayNode('curl_options')
101
                        ->addDefaultsIfNotSet()
102
                        ->children()
103
                            ->booleanNode('return_transfer')->defaultTrue()->end()
104
                            ->integerNode('timeout')->defaultValue(30)->end()
105
                            ->booleanNode("ssl_verifypeer")->defaultFalse()->end()
106
                            ->booleanNode("ssl_verifyhost")->defaultFalse()->end()
107
                        ->end()
108
                    ->end()
109
                    ->arrayNode('endpoints')
110
                    ->useAttributeAsKey('identifier')
111
                    ->prototype('array')
112
                        ->children()
113
                            ->arrayNode('url')
114
                                ->addDefaultsIfNotSet()
115
                                ->canBeEnabled()
116
                                ->children()
117
                                    ->scalarNode('hostname')->defaultNull()->isRequired()->cannotBeEmpty()->end()
118
                                    ->scalarNode('scheme')
119
                                        ->defaultValue("http")
120
                                        ->cannotBeEmpty()
121
                                        ->validate()
122
                                        ->ifNotInArray($schemes)
123
                                            ->thenInvalid('Invalid scheme: "%s", there must be http or https')
124
                                        ->end()
125
                                    ->end()
126
                                    ->integerNode('port')->defaultValue(80)->min(0)->end()
127
                                    ->scalarNode('query_delimiter')
128
                                        ->defaultValue("?")
129
                                        ->cannotBeEmpty()
130
                                        ->validate()
131
                                        ->ifNotInArray($delimiters)
132
                                            ->thenInvalid('Invalid query separator: "%s", there must be ? or /')
133
                                        ->end()
134
                                    ->end()
135
                                ->end()
136
                            ->end()
137
                            ->arrayNode('wsse')
138
                                ->addDefaultsIfNotSet()
139
                                ->canBeEnabled()
140
                                ->children()
141
                                    ->scalarNode('username')->defaultNull()->end()
142
                                    ->scalarNode('password')->defaultNull()->end()
143
                                    ->arrayNode('options')
144
                                        ->addDefaultsIfNotSet()
145
                                        ->children()
146
                                            ->integerNode('nonce_length')->defaultValue(8)->min(1)->isRequired()->cannotBeEmpty()->end()
147
                                            ->scalarNode('nonce_chars')->defaultValue('0123456789abcdef')->end()
148
                                            ->booleanNode('encode_as_64')->defaultTrue()->end()
149
                                        ->end()
150
                                    ->end()
151
                                ->end()
152
                            ->end()
153
                            ->scalarNode('class')->defaultNull()->isRequired()->cannotBeEmpty()->end()
154
                            ->scalarNode('request_format')->defaultValue('json')->end()
155
                            ->scalarNode('response_format')->defaultValue('json')->end()
156
                        ->end()
157
                    ->end()
158
                ->end()
159
            ->end();
160
    }
161
}
162