1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection; |
11
|
|
|
|
12
|
|
|
use RunOpenCode\Bundle\ExchangeRate\Enum\Role; |
13
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Configuration |
19
|
|
|
* |
20
|
|
|
* Configuration tree. |
21
|
|
|
* |
22
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection |
23
|
|
|
*/ |
24
|
|
|
class Configuration implements ConfigurationInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
5 |
|
public function getConfigTreeBuilder() |
30
|
|
|
{ |
31
|
5 |
|
$treeBuilder = new TreeBuilder(); |
32
|
|
|
|
33
|
5 |
|
$rootNode = $treeBuilder->root('run_open_code_exchange_rate'); |
34
|
|
|
|
35
|
|
|
$rootNode |
36
|
5 |
|
->children() |
37
|
5 |
|
->scalarNode('base_currency') |
38
|
5 |
|
->isRequired() |
39
|
5 |
|
->info('Set base currency in which you are doing your business activities.') // TODO Validate!!! |
|
|
|
|
40
|
5 |
|
->end() |
41
|
5 |
|
->scalarNode('repository') |
42
|
5 |
|
->defaultValue('file') |
43
|
5 |
|
->info('Service ID which is in charge for rates persistence.') |
44
|
5 |
|
->end() |
45
|
5 |
|
->append($this->getRatesDefinition()) |
46
|
5 |
|
->append($this->getFileRepositoryDefinition()) |
47
|
5 |
|
->append($this->getDoctrineDbalRepositoryDefinition()) |
48
|
5 |
|
->append($this->getSourcesDefinition()) |
49
|
5 |
|
->append($this->getAccessRolesDefinition()) |
50
|
5 |
|
->arrayNode('form_types') |
51
|
5 |
|
->addDefaultsIfNotSet() |
52
|
5 |
|
->children() |
53
|
5 |
|
->append($this->getSourceTypeDefinition()) |
54
|
5 |
|
->append($this->getRateTypeTypeDefinition()) |
55
|
5 |
|
->append($this->getCurrencyCodeTypeDefinition()) |
56
|
5 |
|
->append($this->getRateTypeDefinition()) |
57
|
5 |
|
->end() |
58
|
5 |
|
->end() |
59
|
5 |
|
->end() |
60
|
5 |
|
->end(); |
61
|
|
|
|
62
|
5 |
|
return $treeBuilder; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Build configuration tree for rates. |
67
|
|
|
* |
68
|
|
|
* @return ArrayNodeDefinition |
69
|
|
|
*/ |
70
|
5 |
|
protected function getRatesDefinition() |
71
|
|
|
{ |
72
|
5 |
|
$node = new ArrayNodeDefinition('rates'); |
73
|
|
|
$node |
|
|
|
|
74
|
5 |
|
->info('Configuration of each individual rate with which you intend to work with.') |
75
|
5 |
|
->requiresAtLeastOneElement() |
76
|
5 |
|
->prototype('array') |
77
|
5 |
|
->children() |
78
|
5 |
|
->scalarNode('currency_code')->isRequired()->end() |
79
|
5 |
|
->scalarNode('rate_type')->isRequired()->end() |
80
|
5 |
|
->scalarNode('source')->isRequired()->end() |
81
|
5 |
|
->arrayNode('extra')->end() |
82
|
5 |
|
->end() |
83
|
5 |
|
->end() |
84
|
5 |
|
->end(); |
85
|
|
|
|
86
|
5 |
|
return $node; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Build configuration tree for file repository. |
91
|
|
|
* |
92
|
|
|
* @return ArrayNodeDefinition |
93
|
|
|
*/ |
94
|
5 |
|
protected function getFileRepositoryDefinition() |
95
|
|
|
{ |
96
|
5 |
|
$node = new ArrayNodeDefinition('file_repository'); |
97
|
|
|
|
98
|
|
|
$node |
99
|
5 |
|
->info('Configuration for file repository (if used).') |
100
|
5 |
|
->addDefaultsIfNotSet() |
101
|
5 |
|
->children() |
102
|
5 |
|
->scalarNode('path') |
103
|
5 |
|
->info('Absolute path to file where database file will be stored.') |
104
|
5 |
|
->defaultValue('%kernel.root_dir%/db/exchange_rates.dat') |
105
|
5 |
|
->end() |
106
|
5 |
|
->end() |
107
|
5 |
|
->end(); |
108
|
|
|
|
109
|
5 |
|
return $node; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Build configuration tree for Doctrine Dbal repository. |
114
|
|
|
* |
115
|
|
|
* @return ArrayNodeDefinition |
116
|
|
|
*/ |
117
|
5 |
|
protected function getDoctrineDbalRepositoryDefinition() |
118
|
|
|
{ |
119
|
5 |
|
$node = new ArrayNodeDefinition('doctrine_dbal_repository'); |
120
|
|
|
|
121
|
|
|
$node |
122
|
5 |
|
->info('Configuration for Doctrine Dbla repository (if used).') |
123
|
5 |
|
->addDefaultsIfNotSet() |
124
|
5 |
|
->children() |
125
|
5 |
|
->scalarNode('connection') |
126
|
5 |
|
->info('Which database connection to use.') |
127
|
5 |
|
->defaultValue('doctrine.dbal.default_connection') |
128
|
5 |
|
->end() |
129
|
5 |
|
->scalarNode('table_name') |
130
|
5 |
|
->info('Which table name to use for storing exchange rates.') |
131
|
5 |
|
->defaultValue('runopencode_exchange_rate') |
132
|
5 |
|
->end() |
133
|
5 |
|
->end() |
134
|
5 |
|
->end(); |
135
|
|
|
|
136
|
5 |
|
return $node; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Build configuration tree for simple sources. |
141
|
|
|
* |
142
|
|
|
* @return ArrayNodeDefinition |
143
|
|
|
*/ |
144
|
5 |
|
protected function getSourcesDefinition() |
145
|
|
|
{ |
146
|
5 |
|
$node = new ArrayNodeDefinition('sources'); |
147
|
|
|
|
148
|
|
|
$node |
149
|
5 |
|
->info('Add sources to sources registry without registering them into service container.') |
150
|
5 |
|
->useAttributeAsKey('name') |
151
|
5 |
|
->prototype('scalar')->end() |
152
|
5 |
|
->end(); |
153
|
|
|
|
154
|
5 |
|
return $node; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Build configuration tree for access roles. |
159
|
|
|
* |
160
|
|
|
* @return ArrayNodeDefinition |
161
|
|
|
*/ |
162
|
5 |
|
protected function getAccessRolesDefinition() |
163
|
|
|
{ |
164
|
5 |
|
$node = new ArrayNodeDefinition('access_roles'); |
165
|
|
|
|
166
|
|
|
$node |
167
|
5 |
|
->info('Configuration of controller access roles.') |
168
|
5 |
|
->addDefaultsIfNotSet() |
169
|
5 |
|
->children() |
170
|
5 |
|
->arrayNode('list') |
171
|
5 |
|
->defaultValue(array(Role::MANAGE_RATE, Role::VIEW_RATE)) |
172
|
5 |
|
->prototype('scalar')->end() |
173
|
5 |
|
->end() |
174
|
5 |
|
->arrayNode('create') |
175
|
5 |
|
->defaultValue(array(Role::MANAGE_RATE, Role::VIEW_RATE)) |
176
|
5 |
|
->prototype('scalar')->end() |
177
|
5 |
|
->end() |
178
|
5 |
|
->arrayNode('edit') |
179
|
5 |
|
->defaultValue(array(Role::MANAGE_RATE, Role::DELETE_RATE)) |
180
|
5 |
|
->prototype('scalar')->end() |
181
|
5 |
|
->end() |
182
|
5 |
|
->arrayNode('delete') |
183
|
5 |
|
->defaultValue(array(Role::MANAGE_RATE, Role::DELETE_RATE)) |
184
|
5 |
|
->prototype('scalar')->end() |
185
|
5 |
|
->end() |
186
|
5 |
|
->end() |
187
|
5 |
|
->end(); |
188
|
|
|
|
189
|
|
|
|
190
|
5 |
|
return $node; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Build configuration tree for "RunOpenCode\Bundle\ExchangeRate\Form\Type\SourceType" default settings. |
195
|
|
|
* |
196
|
|
|
* @return ArrayNodeDefinition |
197
|
|
|
*/ |
198
|
5 |
View Code Duplication |
protected function getSourceTypeDefinition() |
|
|
|
|
199
|
|
|
{ |
200
|
5 |
|
$node = new ArrayNodeDefinition('source_type'); |
201
|
|
|
|
202
|
|
|
$node |
203
|
5 |
|
->info('Modify default "RunOpenCode\\Bundle\\ExchangeRate\\Form\\Type\\SourceType" settings.') |
204
|
5 |
|
->addDefaultsIfNotSet() |
205
|
5 |
|
->children() |
206
|
5 |
|
->scalarNode('choice_translation_domain')->defaultValue('roc_exchange_rate')->end() |
207
|
5 |
|
->arrayNode('preferred_choices')->end() |
208
|
5 |
|
->end() |
209
|
5 |
|
->end(); |
210
|
|
|
|
211
|
5 |
|
return $node; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Build configuration tree for "RunOpenCode\Bundle\ExchangeRate\Form\Type\RateTypeType" default settings. |
216
|
|
|
* |
217
|
|
|
* @return ArrayNodeDefinition |
218
|
|
|
*/ |
219
|
5 |
View Code Duplication |
protected function getRateTypeTypeDefinition() |
|
|
|
|
220
|
|
|
{ |
221
|
5 |
|
$node = new ArrayNodeDefinition('rate_type_type'); |
222
|
|
|
|
223
|
|
|
$node |
224
|
5 |
|
->info('Modify default "RunOpenCode\\Bundle\\ExchangeRate\\Form\\Type\\RateTypeType" settings.') |
225
|
5 |
|
->addDefaultsIfNotSet() |
226
|
5 |
|
->children() |
227
|
5 |
|
->scalarNode('choice_translation_domain')->defaultValue('roc_exchange_rate')->end() |
228
|
5 |
|
->arrayNode('preferred_choices')->end() |
229
|
5 |
|
->end() |
230
|
5 |
|
->end(); |
231
|
|
|
|
232
|
5 |
|
return $node; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Build configuration tree for "RunOpenCode\Bundle\ExchangeRate\Form\Type\CurrencyCodeType" default settings. |
237
|
|
|
* |
238
|
|
|
* @return ArrayNodeDefinition |
239
|
|
|
*/ |
240
|
5 |
View Code Duplication |
protected function getCurrencyCodeTypeDefinition() |
|
|
|
|
241
|
|
|
{ |
242
|
5 |
|
$node = new ArrayNodeDefinition('currency_code_type'); |
243
|
|
|
|
244
|
|
|
$node |
245
|
5 |
|
->info('Modify default "RunOpenCode\\Bundle\\ExchangeRate\\Form\\Type\\CurrencyCodeType" settings.') |
246
|
5 |
|
->addDefaultsIfNotSet() |
247
|
5 |
|
->children() |
248
|
5 |
|
->scalarNode('choice_translation_domain')->defaultValue('roc_exchange_rate')->end() |
249
|
5 |
|
->arrayNode('preferred_choices')->end() |
250
|
5 |
|
->end() |
251
|
5 |
|
->end(); |
252
|
|
|
|
253
|
5 |
|
return $node; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Build configuration tree for "RunOpenCode\Bundle\ExchangeRate\Form\Type\RateType" default settings. |
258
|
|
|
* |
259
|
|
|
* @return ArrayNodeDefinition |
260
|
|
|
*/ |
261
|
5 |
|
protected function getRateTypeDefinition() |
262
|
|
|
{ |
263
|
5 |
|
$node = new ArrayNodeDefinition('rate_type'); |
264
|
|
|
|
265
|
|
|
$node |
266
|
5 |
|
->info('Modify default "RunOpenCode\\Bundle\\ExchangeRate\\Form\\Type\\RateType" settings.') |
267
|
5 |
|
->addDefaultsIfNotSet() |
268
|
5 |
|
->children() |
269
|
5 |
|
->scalarNode('choice_translation_domain')->defaultValue('roc_exchange_rate')->end() |
270
|
5 |
|
->scalarNode('label_format')->defaultValue('{{currency-code}}, {{rate-type}} ({{source}})')->end() |
271
|
5 |
|
->arrayNode('preferred_choices')->end() |
272
|
5 |
|
->end() |
273
|
5 |
|
->end(); |
274
|
|
|
|
275
|
5 |
|
return $node; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.