1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSRestBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\RestBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
17
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
19
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
20
|
|
|
use Symfony\Component\Serializer\Encoder\XmlEncoder; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This class contains the configuration information for the bundle. |
24
|
|
|
* |
25
|
|
|
* This information is solely responsible for how the different configuration |
26
|
|
|
* sections are normalized, and merged. |
27
|
|
|
* |
28
|
|
|
* @author Lukas Kahwe Smith <[email protected]> |
29
|
|
|
* |
30
|
|
|
* @internal |
31
|
|
|
*/ |
32
|
|
|
final class Configuration implements ConfigurationInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Default debug mode value. |
36
|
|
|
* |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
private $debug; |
40
|
|
|
|
41
|
85 |
|
public function __construct(bool $debug) |
42
|
|
|
{ |
43
|
85 |
|
$this->debug = $debug; |
44
|
85 |
|
} |
45
|
|
|
|
46
|
84 |
|
public function getConfigTreeBuilder(): TreeBuilder |
47
|
|
|
{ |
48
|
84 |
|
$treeBuilder = new TreeBuilder('fos_rest'); |
49
|
|
|
|
50
|
84 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
51
|
84 |
|
$rootNode = $treeBuilder->getRootNode(); |
52
|
|
|
} else { |
53
|
|
|
$rootNode = $treeBuilder->root('fos_rest'); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$rootNode |
57
|
84 |
|
->children() |
58
|
84 |
|
->scalarNode('disable_csrf_role')->defaultNull()->end() |
59
|
84 |
|
->arrayNode('access_denied_listener') |
60
|
84 |
|
->canBeEnabled() |
61
|
84 |
|
->setDeprecated('The "%path%.%node%" option is deprecated since FOSRestBundle 2.8.') |
62
|
84 |
|
->beforeNormalization() |
63
|
|
View Code Duplication |
->ifArray()->then(function ($v) { |
64
|
|
|
if (!empty($v) && empty($v['formats'])) { |
65
|
|
|
unset($v['enabled']); |
66
|
|
|
$v = ['enabled' => true, 'formats' => $v]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $v; |
70
|
84 |
|
}) |
71
|
84 |
|
->end() |
72
|
84 |
|
->fixXmlConfig('format', 'formats') |
73
|
84 |
|
->children() |
74
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
75
|
84 |
|
->arrayNode('formats') |
76
|
84 |
|
->useAttributeAsKey('name') |
77
|
84 |
|
->prototype('boolean')->end() |
78
|
84 |
|
->end() |
79
|
84 |
|
->end() |
80
|
84 |
|
->end() |
81
|
84 |
|
->scalarNode('unauthorized_challenge')->defaultNull()->end() |
82
|
84 |
|
->arrayNode('param_fetcher_listener') |
83
|
84 |
|
->beforeNormalization() |
84
|
84 |
|
->ifString() |
85
|
|
View Code Duplication |
->then(function ($v) { |
86
|
1 |
|
return ['enabled' => in_array($v, ['force', 'true']), 'force' => 'force' === $v]; |
87
|
84 |
|
}) |
88
|
84 |
|
->end() |
89
|
84 |
|
->canBeEnabled() |
90
|
84 |
|
->children() |
91
|
84 |
|
->booleanNode('force')->defaultFalse()->end() |
92
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
93
|
84 |
|
->end() |
94
|
84 |
|
->end() |
95
|
84 |
|
->scalarNode('cache_dir')->cannotBeEmpty()->defaultValue('%kernel.cache_dir%/fos_rest')->end() |
96
|
84 |
|
->arrayNode('allowed_methods_listener') |
97
|
84 |
|
->canBeEnabled() |
98
|
84 |
|
->children() |
99
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
100
|
84 |
|
->end() |
101
|
84 |
|
->end() |
102
|
84 |
|
->arrayNode('routing_loader') |
103
|
84 |
|
->addDefaultsIfNotSet() |
104
|
84 |
|
->beforeNormalization() |
105
|
|
|
->ifTrue(function ($v) { return isset($v['enabled']) && false !== $v['enabled']; }) |
106
|
|
|
->then(function ($v) { |
107
|
|
|
@trigger_error('Enabling the route generation feature is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED); |
|
|
|
|
108
|
|
|
|
109
|
|
|
return $v; |
110
|
84 |
|
}) |
111
|
84 |
|
->end() |
112
|
84 |
|
->beforeNormalization() |
113
|
|
|
->ifTrue(function ($v) { return is_bool($v); }) |
114
|
|
|
->then(function ($v) { |
115
|
|
|
return [ |
116
|
66 |
|
'enabled' => $v, |
117
|
|
|
]; |
118
|
84 |
|
}) |
119
|
84 |
|
->end() |
120
|
84 |
|
->children() |
121
|
84 |
|
->booleanNode('enabled') |
122
|
|
|
->defaultValue(function () { |
123
|
7 |
|
@trigger_error('Enabling the route generation feature is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED); |
|
|
|
|
124
|
|
|
|
125
|
7 |
|
return true; |
126
|
84 |
|
}) |
127
|
84 |
|
->end() |
128
|
84 |
|
->scalarNode('default_format')->defaultNull()->end() |
129
|
84 |
|
->scalarNode('prefix_methods')->defaultTrue()->end() |
130
|
84 |
|
->scalarNode('include_format')->defaultTrue()->end() |
131
|
84 |
|
->end() |
132
|
84 |
|
->end() |
133
|
84 |
|
->arrayNode('body_converter') |
134
|
84 |
|
->canBeEnabled() |
135
|
84 |
|
->children() |
136
|
84 |
|
->scalarNode('validate') |
137
|
84 |
|
->defaultFalse() |
138
|
84 |
|
->beforeNormalization() |
139
|
84 |
|
->ifTrue() |
140
|
|
|
->then(function ($value) { |
141
|
3 |
|
if (!class_exists(OptionsResolver::class)) { |
142
|
|
|
throw new InvalidConfigurationException("'body_converter.validate: true' requires OptionsResolver component installation ( composer require symfony/options-resolver )"); |
143
|
|
|
} |
144
|
|
|
|
145
|
3 |
|
return $value; |
146
|
84 |
|
}) |
147
|
84 |
|
->end() |
148
|
84 |
|
->end() |
149
|
84 |
|
->scalarNode('validation_errors_argument')->defaultValue('validationErrors')->end() |
150
|
84 |
|
->end() |
151
|
84 |
|
->end() |
152
|
84 |
|
->arrayNode('service') |
153
|
84 |
|
->addDefaultsIfNotSet() |
154
|
84 |
|
->children() |
155
|
84 |
|
->scalarNode('router')->defaultValue('router')->setDeprecated('The "%path%.%node%" configuration key has been deprecated in FOSRestBundle 2.8.')->end() |
156
|
84 |
|
->scalarNode('templating') |
157
|
84 |
|
->defaultValue('templating') |
158
|
84 |
|
->setDeprecated('The "%path%.%node%" option is deprecated since FOSRestBundle 2.8.') |
159
|
84 |
|
->end() |
160
|
84 |
|
->scalarNode('serializer')->defaultNull()->end() |
161
|
84 |
|
->scalarNode('view_handler')->defaultValue('fos_rest.view_handler.default')->end() |
162
|
84 |
|
->scalarNode('inflector') |
163
|
84 |
|
->defaultValue('fos_rest.inflector.doctrine') |
164
|
84 |
|
->setDeprecated('The "%path%.%node%" option is deprecated since FOSRestBundle 2.8.') |
165
|
84 |
|
->end() |
166
|
84 |
|
->scalarNode('validator')->defaultValue('validator')->end() |
167
|
84 |
|
->end() |
168
|
84 |
|
->end() |
169
|
84 |
|
->arrayNode('serializer') |
170
|
84 |
|
->addDefaultsIfNotSet() |
171
|
84 |
|
->children() |
172
|
84 |
|
->scalarNode('version')->defaultNull()->end() |
173
|
84 |
|
->arrayNode('groups') |
174
|
84 |
|
->prototype('scalar')->end() |
175
|
84 |
|
->end() |
176
|
84 |
|
->booleanNode('serialize_null')->defaultFalse()->end() |
177
|
84 |
|
->end() |
178
|
84 |
|
->end() |
179
|
84 |
|
->arrayNode('zone') |
180
|
84 |
|
->cannotBeOverwritten() |
181
|
84 |
|
->prototype('array') |
182
|
84 |
|
->fixXmlConfig('ip') |
183
|
84 |
|
->children() |
184
|
84 |
|
->scalarNode('path') |
185
|
84 |
|
->defaultNull() |
186
|
84 |
|
->info('use the urldecoded format') |
187
|
84 |
|
->example('^/path to resource/') |
188
|
84 |
|
->end() |
189
|
84 |
|
->scalarNode('host')->defaultNull()->end() |
190
|
84 |
|
->arrayNode('methods') |
191
|
|
|
->beforeNormalization()->ifString()->then(function ($v) { |
192
|
|
|
return preg_split('/\s*,\s*/', $v); |
193
|
84 |
|
})->end() |
194
|
84 |
|
->prototype('scalar')->end() |
195
|
84 |
|
->end() |
196
|
84 |
|
->arrayNode('ips') |
197
|
|
|
->beforeNormalization()->ifString()->then(function ($v) { |
198
|
1 |
|
return array($v); |
199
|
84 |
|
})->end() |
200
|
84 |
|
->prototype('scalar')->end() |
201
|
84 |
|
->end() |
202
|
84 |
|
->end() |
203
|
84 |
|
->end() |
204
|
84 |
|
->end() |
205
|
84 |
|
->end(); |
206
|
|
|
|
207
|
84 |
|
$this->addViewSection($rootNode); |
|
|
|
|
208
|
84 |
|
$this->addExceptionSection($rootNode); |
|
|
|
|
209
|
84 |
|
$this->addBodyListenerSection($rootNode); |
|
|
|
|
210
|
84 |
|
$this->addFormatListenerSection($rootNode); |
|
|
|
|
211
|
84 |
|
$this->addVersioningSection($rootNode); |
|
|
|
|
212
|
|
|
|
213
|
84 |
|
return $treeBuilder; |
214
|
|
|
} |
215
|
|
|
|
216
|
84 |
|
private function addViewSection(ArrayNodeDefinition $rootNode) |
217
|
|
|
{ |
218
|
|
|
$rootNode |
219
|
84 |
|
->children() |
220
|
84 |
|
->arrayNode('view') |
221
|
84 |
|
->fixXmlConfig('format', 'formats') |
222
|
84 |
|
->fixXmlConfig('mime_type', 'mime_types') |
223
|
84 |
|
->fixXmlConfig('templating_format', 'templating_formats') |
224
|
84 |
|
->fixXmlConfig('force_redirect', 'force_redirects') |
225
|
84 |
|
->addDefaultsIfNotSet() |
226
|
84 |
|
->children() |
227
|
84 |
|
->scalarNode('default_engine') |
228
|
84 |
|
->setDeprecated('The "%path%.%node%" option has been deprecated in FOSRestBundle 2.8.') |
229
|
84 |
|
->defaultValue('twig') |
230
|
84 |
|
->end() |
231
|
84 |
|
->arrayNode('force_redirects') |
232
|
84 |
|
->setDeprecated('The "%path%.%node%" option has been deprecated in FOSRestBundle 2.8.') |
233
|
84 |
|
->useAttributeAsKey('name') |
234
|
84 |
|
->defaultValue(['html' => true]) |
235
|
84 |
|
->prototype('boolean')->end() |
236
|
84 |
|
->end() |
237
|
84 |
|
->arrayNode('mime_types') |
238
|
84 |
|
->canBeEnabled() |
239
|
84 |
|
->beforeNormalization() |
240
|
|
View Code Duplication |
->ifArray()->then(function ($v) { |
241
|
1 |
|
if (!empty($v) && empty($v['formats'])) { |
242
|
1 |
|
unset($v['enabled']); |
243
|
1 |
|
$v = ['enabled' => true, 'formats' => $v]; |
244
|
|
|
} |
245
|
|
|
|
246
|
1 |
|
return $v; |
247
|
84 |
|
}) |
248
|
84 |
|
->end() |
249
|
84 |
|
->fixXmlConfig('format', 'formats') |
250
|
84 |
|
->children() |
251
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
252
|
84 |
|
->arrayNode('formats') |
253
|
84 |
|
->useAttributeAsKey('name') |
254
|
84 |
|
->prototype('array') |
255
|
84 |
|
->beforeNormalization() |
256
|
84 |
|
->ifString() |
257
|
|
|
->then(function ($v) { return array($v); }) |
258
|
84 |
|
->end() |
259
|
84 |
|
->prototype('scalar')->end() |
260
|
84 |
|
->end() |
261
|
84 |
|
->end() |
262
|
84 |
|
->end() |
263
|
84 |
|
->end() |
264
|
84 |
|
->arrayNode('formats') |
265
|
84 |
|
->useAttributeAsKey('name') |
266
|
84 |
|
->defaultValue(['json' => true, 'xml' => true]) |
267
|
84 |
|
->prototype('boolean')->end() |
268
|
84 |
|
->end() |
269
|
84 |
|
->arrayNode('templating_formats') |
270
|
84 |
|
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in FOSRestBundle 2.8.') |
271
|
84 |
|
->useAttributeAsKey('name') |
272
|
84 |
|
->defaultValue(['html' => true]) |
273
|
84 |
|
->prototype('boolean')->end() |
274
|
84 |
|
->end() |
275
|
84 |
|
->arrayNode('view_response_listener') |
276
|
84 |
|
->beforeNormalization() |
277
|
84 |
|
->ifString() |
278
|
|
View Code Duplication |
->then(function ($v) { |
279
|
9 |
|
return ['enabled' => in_array($v, ['force', 'true']), 'force' => 'force' === $v]; |
280
|
84 |
|
}) |
281
|
84 |
|
->end() |
282
|
84 |
|
->canBeEnabled() |
283
|
84 |
|
->children() |
284
|
84 |
|
->booleanNode('force')->defaultFalse()->end() |
285
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
286
|
84 |
|
->end() |
287
|
84 |
|
->end() |
288
|
84 |
|
->scalarNode('failed_validation')->defaultValue(Response::HTTP_BAD_REQUEST)->end() |
289
|
84 |
|
->scalarNode('empty_content')->defaultValue(Response::HTTP_NO_CONTENT)->end() |
290
|
84 |
|
->booleanNode('serialize_null')->defaultFalse()->end() |
291
|
84 |
|
->arrayNode('jsonp_handler') |
292
|
84 |
|
->canBeUnset() |
293
|
84 |
|
->children() |
294
|
84 |
|
->scalarNode('callback_param')->defaultValue('callback')->end() |
295
|
84 |
|
->scalarNode('mime_type')->defaultValue('application/javascript+jsonp')->end() |
296
|
84 |
|
->end() |
297
|
84 |
|
->end() |
298
|
84 |
|
->end() |
299
|
84 |
|
->end() |
300
|
84 |
|
->end(); |
301
|
84 |
|
} |
302
|
|
|
|
303
|
84 |
|
private function addBodyListenerSection(ArrayNodeDefinition $rootNode) |
304
|
|
|
{ |
305
|
84 |
|
$decodersDefaultValue = ['json' => 'fos_rest.decoder.json']; |
306
|
84 |
|
if (class_exists(XmlEncoder::class)) { |
307
|
84 |
|
$decodersDefaultValue['xml'] = 'fos_rest.decoder.xml'; |
308
|
|
|
} |
309
|
|
|
$rootNode |
310
|
84 |
|
->children() |
311
|
84 |
|
->arrayNode('body_listener') |
312
|
84 |
|
->fixXmlConfig('decoder', 'decoders') |
313
|
84 |
|
->addDefaultsIfNotSet() |
314
|
84 |
|
->canBeUnset() |
315
|
84 |
|
->treatFalseLike(['enabled' => false]) |
316
|
84 |
|
->treatTrueLike(['enabled' => true]) |
317
|
84 |
|
->treatNullLike(['enabled' => true]) |
318
|
84 |
|
->children() |
319
|
84 |
|
->booleanNode('enabled') |
320
|
|
|
->defaultValue(function () { |
321
|
7 |
|
@trigger_error('The body_listener config has been enabled by default and will be disabled by default in FOSRestBundle 3.0. Please enable or disable it explicitly.', E_USER_DEPRECATED); |
|
|
|
|
322
|
|
|
|
323
|
7 |
|
return true; |
324
|
84 |
|
}) |
325
|
84 |
|
->end() |
326
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
327
|
84 |
|
->scalarNode('default_format')->defaultNull()->end() |
328
|
84 |
|
->booleanNode('throw_exception_on_unsupported_content_type') |
329
|
84 |
|
->defaultFalse() |
330
|
84 |
|
->end() |
331
|
84 |
|
->arrayNode('decoders') |
332
|
84 |
|
->useAttributeAsKey('name') |
333
|
84 |
|
->defaultValue($decodersDefaultValue) |
334
|
84 |
|
->prototype('scalar')->end() |
335
|
84 |
|
->end() |
336
|
84 |
|
->arrayNode('array_normalizer') |
337
|
84 |
|
->addDefaultsIfNotSet() |
338
|
84 |
|
->beforeNormalization() |
339
|
|
|
->ifString()->then(function ($v) { |
340
|
1 |
|
return ['service' => $v]; |
341
|
84 |
|
}) |
342
|
84 |
|
->end() |
343
|
84 |
|
->children() |
344
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
345
|
84 |
|
->booleanNode('forms')->defaultFalse()->end() |
346
|
84 |
|
->end() |
347
|
84 |
|
->end() |
348
|
84 |
|
->end() |
349
|
84 |
|
->end() |
350
|
84 |
|
->end(); |
351
|
84 |
|
} |
352
|
|
|
|
353
|
84 |
|
private function addFormatListenerSection(ArrayNodeDefinition $rootNode) |
354
|
|
|
{ |
355
|
|
|
$rootNode |
356
|
84 |
|
->children() |
357
|
84 |
|
->arrayNode('format_listener') |
358
|
84 |
|
->fixXmlConfig('rule', 'rules') |
359
|
84 |
|
->addDefaultsIfNotSet() |
360
|
84 |
|
->canBeUnset() |
361
|
84 |
|
->beforeNormalization() |
362
|
|
|
->ifTrue(function ($v) { |
363
|
|
|
// check if we got an assoc array in rules |
364
|
9 |
|
return isset($v['rules']) |
365
|
9 |
|
&& is_array($v['rules']) |
366
|
9 |
|
&& array_keys($v['rules']) !== range(0, count($v['rules']) - 1); |
367
|
84 |
|
}) |
368
|
|
|
->then(function ($v) { |
369
|
1 |
|
$v['rules'] = [$v['rules']]; |
370
|
|
|
|
371
|
1 |
|
return $v; |
372
|
84 |
|
}) |
373
|
84 |
|
->end() |
374
|
84 |
|
->canBeEnabled() |
375
|
84 |
|
->children() |
376
|
84 |
|
->scalarNode('service')->defaultNull()->end() |
377
|
84 |
|
->arrayNode('rules') |
378
|
84 |
|
->performNoDeepMerging() |
379
|
84 |
|
->prototype('array') |
380
|
84 |
|
->fixXmlConfig('priority', 'priorities') |
381
|
84 |
|
->fixXmlConfig('attribute', 'attributes') |
382
|
84 |
|
->children() |
383
|
84 |
|
->scalarNode('path')->defaultNull()->info('URL path info')->end() |
384
|
84 |
|
->scalarNode('host')->defaultNull()->info('URL host name')->end() |
385
|
84 |
|
->variableNode('methods')->defaultNull()->info('Method for URL')->end() |
386
|
84 |
|
->arrayNode('attributes') |
387
|
84 |
|
->useAttributeAsKey('name') |
388
|
84 |
|
->prototype('variable')->end() |
389
|
84 |
|
->end() |
390
|
84 |
|
->booleanNode('stop')->defaultFalse()->end() |
391
|
84 |
|
->booleanNode('prefer_extension')->defaultTrue()->end() |
392
|
84 |
|
->scalarNode('fallback_format')->defaultValue('html')->end() |
393
|
84 |
|
->arrayNode('priorities') |
394
|
|
|
->beforeNormalization()->ifString()->then(function ($v) { |
395
|
|
|
return preg_split('/\s*,\s*/', $v); |
396
|
84 |
|
})->end() |
397
|
84 |
|
->prototype('scalar')->end() |
398
|
84 |
|
->end() |
399
|
84 |
|
->end() |
400
|
84 |
|
->end() |
401
|
84 |
|
->end() |
402
|
84 |
|
->end() |
403
|
84 |
|
->end() |
404
|
84 |
|
->end(); |
405
|
84 |
|
} |
406
|
|
|
|
407
|
84 |
|
private function addVersioningSection(ArrayNodeDefinition $rootNode) |
408
|
|
|
{ |
409
|
|
|
$rootNode |
410
|
84 |
|
->children() |
411
|
84 |
|
->arrayNode('versioning') |
412
|
84 |
|
->canBeEnabled() |
413
|
84 |
|
->children() |
414
|
84 |
|
->scalarNode('default_version')->defaultNull()->end() |
415
|
84 |
|
->arrayNode('resolvers') |
416
|
84 |
|
->addDefaultsIfNotSet() |
417
|
84 |
|
->children() |
418
|
84 |
|
->arrayNode('query') |
419
|
84 |
|
->canBeDisabled() |
420
|
84 |
|
->children() |
421
|
84 |
|
->scalarNode('parameter_name')->defaultValue('version')->end() |
422
|
84 |
|
->end() |
423
|
84 |
|
->end() |
424
|
84 |
|
->arrayNode('custom_header') |
425
|
84 |
|
->canBeDisabled() |
426
|
84 |
|
->children() |
427
|
84 |
|
->scalarNode('header_name')->defaultValue('X-Accept-Version')->end() |
428
|
84 |
|
->end() |
429
|
84 |
|
->end() |
430
|
84 |
|
->arrayNode('media_type') |
431
|
84 |
|
->canBeDisabled() |
432
|
84 |
|
->children() |
433
|
84 |
|
->scalarNode('regex')->defaultValue('/(v|version)=(?P<version>[0-9\.]+)/')->end() |
434
|
84 |
|
->end() |
435
|
84 |
|
->end() |
436
|
84 |
|
->end() |
437
|
84 |
|
->end() |
438
|
84 |
|
->arrayNode('guessing_order') |
439
|
84 |
|
->defaultValue(['query', 'custom_header', 'media_type']) |
440
|
84 |
|
->validate() |
441
|
|
|
->ifTrue(function ($v) { |
442
|
|
|
foreach ($v as $resolver) { |
443
|
|
|
if (!in_array($resolver, ['query', 'custom_header', 'media_type'])) { |
444
|
|
|
return true; |
445
|
|
|
} |
446
|
|
|
} |
447
|
84 |
|
}) |
448
|
84 |
|
->thenInvalid('Versioning guessing order can only contain "query", "custom_header", "media_type".') |
449
|
84 |
|
->end() |
450
|
84 |
|
->prototype('scalar')->end() |
451
|
84 |
|
->end() |
452
|
84 |
|
->end() |
453
|
84 |
|
->end() |
454
|
84 |
|
->end(); |
455
|
84 |
|
} |
456
|
|
|
|
457
|
84 |
|
private function addExceptionSection(ArrayNodeDefinition $rootNode) |
458
|
|
|
{ |
459
|
|
|
$rootNode |
460
|
84 |
|
->children() |
461
|
84 |
|
->arrayNode('exception') |
462
|
84 |
|
->fixXmlConfig('code', 'codes') |
463
|
84 |
|
->fixXmlConfig('message', 'messages') |
464
|
84 |
|
->addDefaultsIfNotSet() |
465
|
84 |
|
->canBeEnabled() |
466
|
84 |
|
->children() |
467
|
84 |
|
->booleanNode('map_exception_codes') |
468
|
84 |
|
->defaultFalse() |
469
|
84 |
|
->info('Enables an event listener that maps exception codes to response status codes based on the map configured with the "fos_rest.exception.codes" option.') |
470
|
84 |
|
->end() |
471
|
84 |
|
->booleanNode('exception_listener') |
472
|
|
|
->defaultValue(function () { |
473
|
15 |
|
@trigger_error('Enabling the "fos_rest.exception.exception_listener" option is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED); |
|
|
|
|
474
|
|
|
|
475
|
15 |
|
return true; |
476
|
84 |
|
}) |
477
|
84 |
|
->beforeNormalization() |
478
|
84 |
|
->ifTrue() |
479
|
|
|
->then(function ($v) { |
480
|
|
|
@trigger_error('Enabling the "fos_rest.exception.exception_listener" option is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED); |
|
|
|
|
481
|
|
|
|
482
|
|
|
return $v; |
483
|
84 |
|
}) |
484
|
84 |
|
->end() |
485
|
84 |
|
->end() |
486
|
84 |
|
->scalarNode('exception_controller') |
487
|
84 |
|
->defaultNull() |
488
|
84 |
|
->setDeprecated('The "%path%.%node%" option is deprecated since FOSRestBundle 2.8.') |
489
|
84 |
|
->end() |
490
|
84 |
|
->booleanNode('serialize_exceptions') |
491
|
|
|
->defaultValue(function () { |
492
|
10 |
|
@trigger_error('Enabling the "fos_rest.exception.serialize_exceptions" option is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED); |
|
|
|
|
493
|
|
|
|
494
|
10 |
|
return true; |
495
|
84 |
|
}) |
496
|
84 |
|
->beforeNormalization() |
497
|
84 |
|
->ifTrue() |
498
|
|
|
->then(function ($v) { |
499
|
8 |
|
@trigger_error('Enabling the "fos_rest.exception.serialize_exceptions" option is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED); |
|
|
|
|
500
|
|
|
|
501
|
8 |
|
return $v; |
502
|
84 |
|
}) |
503
|
84 |
|
->end() |
504
|
84 |
|
->end() |
505
|
84 |
|
->enumNode('flatten_exception_format') |
506
|
84 |
|
->defaultValue('legacy') |
507
|
84 |
|
->values(['legacy', 'rfc7807']) |
508
|
84 |
|
->end() |
509
|
84 |
|
->scalarNode('service') |
510
|
84 |
|
->defaultNull() |
511
|
84 |
|
->setDeprecated('The "%path%.%node%" option is deprecated since FOSRestBundle 2.8.') |
512
|
84 |
|
->end() |
513
|
84 |
|
->booleanNode('serializer_error_renderer')->defaultValue(false)->end() |
514
|
84 |
|
->arrayNode('codes') |
515
|
84 |
|
->useAttributeAsKey('name') |
516
|
84 |
|
->beforeNormalization() |
517
|
84 |
|
->ifArray() |
518
|
|
|
->then(function (array $items) { |
519
|
13 |
|
foreach ($items as &$item) { |
520
|
13 |
|
if (is_int($item)) { |
521
|
3 |
|
continue; |
522
|
|
|
} |
523
|
|
|
|
524
|
10 |
|
if (!defined(sprintf('%s::%s', Response::class, $item))) { |
525
|
9 |
|
throw new InvalidConfigurationException(sprintf('Invalid HTTP code in fos_rest.exception.codes, see %s for all valid codes.', Response::class)); |
526
|
|
|
} |
527
|
|
|
|
528
|
1 |
|
$item = constant(sprintf('%s::%s', Response::class, $item)); |
529
|
|
|
} |
530
|
|
|
|
531
|
4 |
|
return $items; |
532
|
84 |
|
}) |
533
|
84 |
|
->end() |
534
|
84 |
|
->prototype('integer')->end() |
535
|
|
|
|
536
|
84 |
|
->validate() |
537
|
84 |
|
->ifArray() |
538
|
|
|
->then(function (array $items) { |
539
|
4 |
|
foreach ($items as $class => $code) { |
540
|
4 |
|
$this->testExceptionExists($class); |
541
|
|
|
} |
542
|
|
|
|
543
|
3 |
|
return $items; |
544
|
84 |
|
}) |
545
|
84 |
|
->end() |
546
|
84 |
|
->end() |
547
|
84 |
|
->arrayNode('messages') |
548
|
84 |
|
->useAttributeAsKey('name') |
549
|
84 |
|
->prototype('boolean')->end() |
550
|
84 |
|
->validate() |
551
|
84 |
|
->ifArray() |
552
|
|
|
->then(function (array $items) { |
553
|
12 |
|
foreach ($items as $class => $nomatter) { |
554
|
12 |
|
$this->testExceptionExists($class); |
555
|
|
|
} |
556
|
|
|
|
557
|
11 |
|
return $items; |
558
|
84 |
|
}) |
559
|
84 |
|
->end() |
560
|
84 |
|
->end() |
561
|
84 |
|
->booleanNode('debug') |
562
|
84 |
|
->defaultValue($this->debug) |
563
|
84 |
|
->end() |
564
|
84 |
|
->end() |
565
|
84 |
|
->end() |
566
|
84 |
|
->end(); |
567
|
84 |
|
} |
568
|
|
|
|
569
|
16 |
|
private function testExceptionExists(string $throwable) |
570
|
|
|
{ |
571
|
16 |
|
if (!is_subclass_of($throwable, \Throwable::class)) { |
|
|
|
|
572
|
2 |
|
throw new InvalidConfigurationException(sprintf('FOSRestBundle exception mapper: Could not load class "%s" or the class does not extend from "%s". Most probably this is a configuration problem.', $throwable, \Throwable::class)); |
573
|
|
|
} |
574
|
14 |
|
} |
575
|
|
|
} |
576
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.