|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lexik\Bundle\PayboxBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
6
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* This is the class that validates and merges configuration from your app/config files |
|
10
|
|
|
* |
|
11
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} |
|
12
|
|
|
*/ |
|
13
|
|
|
class Configuration implements ConfigurationInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritDoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
public function getConfigTreeBuilder() |
|
19
|
|
|
{ |
|
20
|
|
|
$treeBuilder = new TreeBuilder(); |
|
21
|
|
|
$rootNode = $treeBuilder->root('lexik_paybox'); |
|
22
|
|
|
|
|
23
|
|
|
$rootNode |
|
24
|
|
|
->addDefaultsIfNotSet() |
|
25
|
|
|
->children() |
|
26
|
|
|
->append($this->createAccountsNode()) |
|
27
|
|
|
->end() |
|
28
|
|
|
; |
|
29
|
|
|
|
|
30
|
|
|
return $treeBuilder; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private function createAccountsNode() |
|
34
|
|
|
{ |
|
35
|
|
|
$treeBuilder = new TreeBuilder(); |
|
36
|
|
|
$node = $treeBuilder->root('accounts'); |
|
37
|
|
|
|
|
38
|
|
|
$node |
|
|
|
|
|
|
39
|
|
|
->useAttributeAsKey('name') |
|
40
|
|
|
->prototype('array') |
|
41
|
|
|
->children() |
|
42
|
|
|
->scalarNode('public_key')->defaultValue(null)->end() |
|
43
|
|
|
|
|
44
|
|
|
->arrayNode('parameters') |
|
45
|
|
|
->isRequired() |
|
46
|
|
|
->children() |
|
47
|
|
|
->scalarNode('production')->defaultValue(false)->end() |
|
48
|
|
|
->arrayNode('currencies') |
|
49
|
|
|
->defaultValue(array( |
|
50
|
|
|
'036', // AUD |
|
51
|
|
|
'124', // CAD |
|
52
|
|
|
'756', // CHF |
|
53
|
|
|
'826', // GBP |
|
54
|
|
|
'840', // USD |
|
55
|
|
|
'978', // EUR |
|
56
|
|
|
)) |
|
57
|
|
|
->prototype('scalar')->end() |
|
58
|
|
|
->end() |
|
59
|
|
|
->scalarNode('site')->isRequired()->end() |
|
60
|
|
|
->scalarNode('rank')->defaultValue(null)->end() |
|
61
|
|
|
->scalarNode('rang')->defaultValue(null)->end() |
|
62
|
|
|
->scalarNode('login')->defaultValue(null)->end() |
|
63
|
|
|
->scalarNode('cle')->defaultValue(null)->end() |
|
64
|
|
|
->arrayNode('hmac') |
|
65
|
|
|
->isRequired() |
|
66
|
|
|
->children() |
|
67
|
|
|
->scalarNode('algorithm')->defaultValue('sha512')->end() |
|
68
|
|
|
->scalarNode('key')->isRequired()->end() |
|
69
|
|
|
->scalarNode('signature_name')->defaultValue('Sign')->end() |
|
70
|
|
|
->end() |
|
71
|
|
|
->end() |
|
72
|
|
|
->end() |
|
73
|
|
|
->end() |
|
74
|
|
|
|
|
75
|
|
|
->arrayNode('servers') |
|
76
|
|
|
->addDefaultsIfNotSet() |
|
77
|
|
|
->children() |
|
78
|
|
|
|
|
79
|
|
|
->arrayNode('system') |
|
80
|
|
|
->addDefaultsIfNotSet() |
|
81
|
|
|
->children() |
|
82
|
|
|
->arrayNode('primary') |
|
83
|
|
|
->addDefaultsIfNotSet() |
|
84
|
|
|
->children() |
|
85
|
|
|
->scalarNode('protocol')->defaultValue('https')->end() |
|
86
|
|
|
->scalarNode('host')->defaultValue('tpeweb.paybox.com')->end() |
|
87
|
|
|
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end() |
|
88
|
|
|
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end() |
|
89
|
|
|
->scalarNode('test_path')->defaultValue('/load.html')->end() |
|
90
|
|
|
->end() |
|
91
|
|
|
->end() |
|
92
|
|
|
->arrayNode('secondary') |
|
93
|
|
|
->addDefaultsIfNotSet() |
|
94
|
|
|
->children() |
|
95
|
|
|
->scalarNode('protocol')->defaultValue('https')->end() |
|
96
|
|
|
->scalarNode('host')->defaultValue('tpeweb1.paybox.com')->end() |
|
97
|
|
|
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end() |
|
98
|
|
|
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end() |
|
99
|
|
|
->scalarNode('test_path')->defaultValue('/load.html')->end() |
|
100
|
|
|
->end() |
|
101
|
|
|
->end() |
|
102
|
|
|
->arrayNode('preprod') |
|
103
|
|
|
->addDefaultsIfNotSet() |
|
104
|
|
|
->children() |
|
105
|
|
|
->scalarNode('protocol')->defaultValue('https')->end() |
|
106
|
|
|
->scalarNode('host')->defaultValue('preprod-tpeweb.paybox.com')->end() |
|
107
|
|
|
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end() |
|
108
|
|
|
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end() |
|
109
|
|
|
->scalarNode('test_path')->defaultValue('/load.html')->end() |
|
110
|
|
|
->end() |
|
111
|
|
|
->end() |
|
112
|
|
|
->end() |
|
113
|
|
|
->end() |
|
114
|
|
|
|
|
115
|
|
|
->arrayNode('direct_plus') |
|
116
|
|
|
->addDefaultsIfNotSet() |
|
117
|
|
|
->children() |
|
118
|
|
|
->arrayNode('primary') |
|
119
|
|
|
->addDefaultsIfNotSet() |
|
120
|
|
|
->children() |
|
121
|
|
|
->scalarNode('protocol')->defaultValue('https')->end() |
|
122
|
|
|
->scalarNode('host')->defaultValue('ppps.paybox.com')->end() |
|
123
|
|
|
->scalarNode('api_path')->defaultValue('/PPPS.php')->end() |
|
124
|
|
|
->end() |
|
125
|
|
|
->end() |
|
126
|
|
|
->arrayNode('secondary') |
|
127
|
|
|
->addDefaultsIfNotSet() |
|
128
|
|
|
->children() |
|
129
|
|
|
->scalarNode('protocol')->defaultValue('https')->end() |
|
130
|
|
|
->scalarNode('host')->defaultValue('ppps1.paybox.com')->end() |
|
131
|
|
|
->scalarNode('api_path')->defaultValue('/PPPS.php')->end() |
|
132
|
|
|
->end() |
|
133
|
|
|
->end() |
|
134
|
|
|
->arrayNode('preprod') |
|
135
|
|
|
->addDefaultsIfNotSet() |
|
136
|
|
|
->children() |
|
137
|
|
|
->scalarNode('protocol')->defaultValue('https')->end() |
|
138
|
|
|
->scalarNode('host')->defaultValue('preprod-ppps.paybox.com')->end() |
|
139
|
|
|
->scalarNode('api_path')->defaultValue('/PPPS.php')->end() |
|
140
|
|
|
->end() |
|
141
|
|
|
->end() |
|
142
|
|
|
->end() |
|
143
|
|
|
->end() |
|
144
|
|
|
|
|
145
|
|
|
->end() |
|
146
|
|
|
->end() |
|
147
|
|
|
|
|
148
|
|
|
->scalarNode('transport') |
|
149
|
|
|
->defaultValue('Lexik\Bundle\PayboxBundle\Transport\CurlTransport') |
|
150
|
|
|
->validate() |
|
151
|
|
|
->ifTrue(function($v) { return !class_exists($v); }) |
|
152
|
|
|
->thenInvalid('Invalid "transport" parameter.') |
|
153
|
|
|
->end() |
|
154
|
|
|
->end() |
|
155
|
|
|
->end() |
|
156
|
|
|
->end() |
|
157
|
|
|
; |
|
158
|
|
|
|
|
159
|
|
|
return $node; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: