|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use Assert\Assertion; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* This helper will help you to create services configuration. |
|
19
|
|
|
*/ |
|
20
|
|
|
final class ConfigurationHelper |
|
21
|
|
|
{ |
|
22
|
|
|
const BUNDLE_ALIAS = 'jose'; |
|
23
|
|
|
/** |
|
24
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
25
|
|
|
* @param string $name |
|
26
|
|
|
* @param string[] $header_checkers |
|
27
|
|
|
* @param string[] $claim_checkers |
|
28
|
|
|
* @param bool $is_public |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function addChecker(ContainerBuilder $container, $name, array $header_checkers, array $claim_checkers, $is_public = true) |
|
31
|
|
|
{ |
|
32
|
|
|
$config = self::getCheckerConfiguration($name, $header_checkers, $claim_checkers, $is_public); |
|
33
|
|
|
self::updateJoseConfiguration($container, $config, 'checkers'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
38
|
|
|
* @param string $name |
|
39
|
|
|
* @param string[] $signature_algorithms |
|
40
|
|
|
* @param bool $create_verifier |
|
41
|
|
|
* @param bool $is_public |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function addSigner(ContainerBuilder $container, $name, array $signature_algorithms, $create_verifier = false, $is_public = true) |
|
44
|
|
|
{ |
|
45
|
|
|
$config = self::getSignerConfiguration($name, $signature_algorithms, $create_verifier, $is_public); |
|
46
|
|
|
self::updateJoseConfiguration($container, $config, 'signers'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
51
|
|
|
* @param string $name |
|
52
|
|
|
* @param string[] $signature_algorithms |
|
53
|
|
|
* @param bool $is_public |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function addVerifier(ContainerBuilder $container, $name, array $signature_algorithms, $is_public = true) |
|
56
|
|
|
{ |
|
57
|
|
|
$config = self::getVerifierConfiguration($name, $signature_algorithms, $is_public); |
|
58
|
|
|
self::updateJoseConfiguration($container, $config, 'verifiers'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
63
|
|
|
* @param string $name |
|
64
|
|
|
* @param string[] $key_encryption_algorithms |
|
65
|
|
|
* @param string[] $content_encryption_algorithms |
|
66
|
|
|
* @param string[] $compression_methods |
|
67
|
|
|
* @param bool $create_decrypter |
|
68
|
|
|
* @param bool $is_public |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function addEncrypter(ContainerBuilder $container, $name, array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF'], $create_decrypter = false, $is_public = true) |
|
71
|
|
|
{ |
|
72
|
|
|
$config = self::getEncrypterConfiguration($name, $key_encryption_algorithms, $content_encryption_algorithms, $compression_methods, $create_decrypter, $is_public); |
|
73
|
|
|
self::updateJoseConfiguration($container, $config, 'encrypters'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* @param string[] $key_encryption_algorithms |
|
80
|
|
|
* @param string[] $content_encryption_algorithms |
|
81
|
|
|
* @param string[] $compression_methods |
|
82
|
|
|
* @param bool $is_public |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function addDecrypter(ContainerBuilder $container, $name, array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF'], $is_public = true) |
|
85
|
|
|
{ |
|
86
|
|
|
$config = self::getDecrypterConfiguration($name, $key_encryption_algorithms, $content_encryption_algorithms, $compression_methods, $is_public); |
|
87
|
|
|
self::updateJoseConfiguration($container, $config, 'decrypters'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
92
|
|
|
* @param string $name |
|
93
|
|
|
* @param string $signer |
|
94
|
|
|
* @param string|null $encrypter |
|
95
|
|
|
* @param bool $is_public |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function addJWTCreator(ContainerBuilder $container, $name, $signer, $encrypter = null, $is_public = true) |
|
98
|
|
|
{ |
|
99
|
|
|
$config = self::getJWTCreatorConfiguration($name, $signer, $encrypter, $is_public); |
|
100
|
|
|
self::updateJoseConfiguration($container, $config, 'jwt_creators'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
105
|
|
|
* @param string $name |
|
106
|
|
|
* @param string $verifier |
|
107
|
|
|
* @param string $checker |
|
108
|
|
|
* @param string|null $decrypter |
|
109
|
|
|
* @param bool $is_public |
|
110
|
|
|
*/ |
|
111
|
|
|
public static function addJWTLoader(ContainerBuilder $container, $name, $verifier, $checker, $decrypter = null, $is_public = true) |
|
112
|
|
|
{ |
|
113
|
|
|
$config = self::getJWTLoaderConfiguration($name, $verifier, $checker, $decrypter, $is_public); |
|
114
|
|
|
self::updateJoseConfiguration($container, $config, 'jwt_loaders'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
119
|
|
|
* @param string $name |
|
120
|
|
|
* @param string $storage_path |
|
121
|
|
|
* @param int $nb_keys |
|
122
|
|
|
* @param array $key_configuration |
|
123
|
|
|
* @param bool $is_rotatable |
|
124
|
|
|
* @param bool $is_public |
|
125
|
|
|
*/ |
|
126
|
|
|
public static function addRandomJWKSet(ContainerBuilder $container, $name, $storage_path, $nb_keys, array $key_configuration, $is_rotatable = false, $is_public = true) |
|
127
|
|
|
{ |
|
128
|
|
|
$config = self::getRandomJWKSetConfiguration($name, $storage_path, $nb_keys, $key_configuration, $is_rotatable, $is_public); |
|
129
|
|
|
self::updateJoseConfiguration($container, $config, 'key_sets'); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
134
|
|
|
* @param string $name |
|
135
|
|
|
* @param string $jwkset |
|
136
|
|
|
* @param bool $is_public |
|
137
|
|
|
*/ |
|
138
|
|
|
public static function addPublicJWKSet(ContainerBuilder $container, $name, $jwkset, $is_public = true) |
|
139
|
|
|
{ |
|
140
|
|
|
$config = self::getPublicJWKSetConfiguration($name, $jwkset, $is_public); |
|
141
|
|
|
self::updateJoseConfiguration($container, $config, 'key_sets'); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
146
|
|
|
* @param string $name |
|
147
|
|
|
* @param string[] $jwksets |
|
148
|
|
|
* @param bool $is_public |
|
149
|
|
|
*/ |
|
150
|
|
|
public static function addJWKSets(ContainerBuilder $container, $name, array $jwksets, $is_public = true) |
|
151
|
|
|
{ |
|
152
|
|
|
$config = self::getJWKSetsConfiguration($name, $jwksets, $is_public); |
|
153
|
|
|
self::updateJoseConfiguration($container, $config, 'key_sets'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param string $name |
|
158
|
|
|
* @param string[] $header_checkers |
|
159
|
|
|
* @param string[] $claim_checkers |
|
160
|
|
|
* @param bool $is_public |
|
161
|
|
|
* |
|
162
|
|
|
* @return array |
|
163
|
|
|
*/ |
|
164
|
|
|
private static function getCheckerConfiguration($name, array $header_checkers, array $claim_checkers, $is_public = true) |
|
165
|
|
|
{ |
|
166
|
|
|
self::checkParameters($name, $is_public); |
|
167
|
|
|
Assertion::allString($header_checkers); |
|
168
|
|
|
Assertion::allString($claim_checkers); |
|
169
|
|
|
|
|
170
|
|
|
return [ |
|
171
|
|
|
self::BUNDLE_ALIAS => [ |
|
172
|
|
|
'checkers' => [ |
|
173
|
|
|
$name => [ |
|
174
|
|
|
'is_public' => $is_public, |
|
175
|
|
|
'claims' => $claim_checkers, |
|
176
|
|
|
'headers' => $header_checkers, |
|
177
|
|
|
], |
|
178
|
|
|
], |
|
179
|
|
|
], |
|
180
|
|
|
]; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param string $name |
|
185
|
|
|
* @param string[] $signature_algorithms |
|
186
|
|
|
* @param bool $create_verifier |
|
187
|
|
|
* @param bool $is_public |
|
188
|
|
|
* |
|
189
|
|
|
* @return array |
|
190
|
|
|
*/ |
|
191
|
|
|
private static function getSignerConfiguration($name, array $signature_algorithms, $create_verifier = false, $is_public = true) |
|
192
|
|
|
{ |
|
193
|
|
|
self::checkParameters($name, $is_public); |
|
194
|
|
|
Assertion::allString($signature_algorithms); |
|
195
|
|
|
Assertion::notEmpty($signature_algorithms); |
|
196
|
|
|
Assertion::boolean($create_verifier); |
|
197
|
|
|
|
|
198
|
|
|
return [ |
|
199
|
|
|
self::BUNDLE_ALIAS => [ |
|
200
|
|
|
'signers' => [ |
|
201
|
|
|
$name => [ |
|
202
|
|
|
'is_public' => $is_public, |
|
203
|
|
|
'algorithms' => $signature_algorithms, |
|
204
|
|
|
'create_verifier' => $create_verifier, |
|
205
|
|
|
], |
|
206
|
|
|
], |
|
207
|
|
|
], |
|
208
|
|
|
]; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param string $name |
|
213
|
|
|
* @param string[] $signature_algorithms |
|
214
|
|
|
* @param bool $is_public |
|
215
|
|
|
* |
|
216
|
|
|
* @return array |
|
217
|
|
|
*/ |
|
218
|
|
|
private static function getVerifierConfiguration($name, array $signature_algorithms, $is_public = true) |
|
219
|
|
|
{ |
|
220
|
|
|
self::checkParameters($name, $is_public); |
|
221
|
|
|
Assertion::allString($signature_algorithms); |
|
222
|
|
|
Assertion::notEmpty($signature_algorithms); |
|
223
|
|
|
|
|
224
|
|
|
return [ |
|
225
|
|
|
self::BUNDLE_ALIAS => [ |
|
226
|
|
|
'verifiers' => [ |
|
227
|
|
|
$name => [ |
|
228
|
|
|
'is_public' => $is_public, |
|
229
|
|
|
'algorithms' => $signature_algorithms, |
|
230
|
|
|
], |
|
231
|
|
|
], |
|
232
|
|
|
], |
|
233
|
|
|
]; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param string $name |
|
238
|
|
|
* @param string[] $key_encryption_algorithms |
|
239
|
|
|
* @param string[] $content_encryption_algorithms |
|
240
|
|
|
* @param string[] $compression_methods |
|
241
|
|
|
* @param bool $create_decrypter |
|
242
|
|
|
* @param bool $is_public |
|
243
|
|
|
* |
|
244
|
|
|
* @return array |
|
245
|
|
|
*/ |
|
246
|
|
|
private static function getEncrypterConfiguration($name, array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF'], $create_decrypter = false, $is_public = true) |
|
247
|
|
|
{ |
|
248
|
|
|
self::checkParameters($name, $is_public); |
|
249
|
|
|
Assertion::allString($key_encryption_algorithms); |
|
250
|
|
|
Assertion::notEmpty($key_encryption_algorithms); |
|
251
|
|
|
Assertion::allString($content_encryption_algorithms); |
|
252
|
|
|
Assertion::notEmpty($content_encryption_algorithms); |
|
253
|
|
|
Assertion::boolean($create_decrypter); |
|
254
|
|
|
|
|
255
|
|
|
return [ |
|
256
|
|
|
self::BUNDLE_ALIAS => [ |
|
257
|
|
|
'encrypters' => [ |
|
258
|
|
|
$name => [ |
|
259
|
|
|
'is_public' => $is_public, |
|
260
|
|
|
'key_encryption_algorithms' => $key_encryption_algorithms, |
|
261
|
|
|
'content_encryption_algorithms' => $content_encryption_algorithms, |
|
262
|
|
|
'compression_methods' => $compression_methods, |
|
263
|
|
|
'create_decrypter' => $create_decrypter, |
|
264
|
|
|
], |
|
265
|
|
|
], |
|
266
|
|
|
], |
|
267
|
|
|
]; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @param string $name |
|
272
|
|
|
* @param string[] $key_encryption_algorithms |
|
273
|
|
|
* @param string[] $content_encryption_algorithms |
|
274
|
|
|
* @param string[] $compression_methods |
|
275
|
|
|
* @param bool $is_public |
|
276
|
|
|
* |
|
277
|
|
|
* @return array |
|
278
|
|
|
*/ |
|
279
|
|
|
private static function getDecrypterConfiguration($name, array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF'], $is_public = true) |
|
280
|
|
|
{ |
|
281
|
|
|
self::checkParameters($name, $is_public); |
|
282
|
|
|
Assertion::allString($key_encryption_algorithms); |
|
283
|
|
|
Assertion::notEmpty($key_encryption_algorithms); |
|
284
|
|
|
Assertion::allString($content_encryption_algorithms); |
|
285
|
|
|
Assertion::notEmpty($content_encryption_algorithms); |
|
286
|
|
|
|
|
287
|
|
|
return [ |
|
288
|
|
|
self::BUNDLE_ALIAS => [ |
|
289
|
|
|
'decrypters' => [ |
|
290
|
|
|
$name => [ |
|
291
|
|
|
'is_public' => $is_public, |
|
292
|
|
|
'key_encryption_algorithms' => $key_encryption_algorithms, |
|
293
|
|
|
'content_encryption_algorithms' => $content_encryption_algorithms, |
|
294
|
|
|
'compression_methods' => $compression_methods, |
|
295
|
|
|
], |
|
296
|
|
|
], |
|
297
|
|
|
], |
|
298
|
|
|
]; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @param string $name |
|
303
|
|
|
* @param string $signer |
|
304
|
|
|
* @param string|null $encrypter |
|
305
|
|
|
* @param bool $is_public |
|
306
|
|
|
* |
|
307
|
|
|
* @return array |
|
308
|
|
|
*/ |
|
309
|
|
|
private static function getJWTCreatorConfiguration($name, $signer, $encrypter = null, $is_public = true) |
|
310
|
|
|
{ |
|
311
|
|
|
self::checkParameters($name, $is_public); |
|
312
|
|
|
Assertion::string($signer); |
|
313
|
|
|
Assertion::notEmpty($signer); |
|
314
|
|
|
Assertion::nullOrString($encrypter); |
|
315
|
|
|
|
|
316
|
|
|
return [ |
|
317
|
|
|
self::BUNDLE_ALIAS => [ |
|
318
|
|
|
'jwt_creators' => [ |
|
319
|
|
|
$name => [ |
|
320
|
|
|
'is_public' => $is_public, |
|
321
|
|
|
'signer' => $signer, |
|
322
|
|
|
'encrypter' => $encrypter, |
|
323
|
|
|
], |
|
324
|
|
|
], |
|
325
|
|
|
], |
|
326
|
|
|
]; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* @param string $name |
|
331
|
|
|
* @param string $verifier |
|
332
|
|
|
* @param string $checker |
|
333
|
|
|
* @param string|null $decrypter |
|
334
|
|
|
* @param bool $is_public |
|
335
|
|
|
* |
|
336
|
|
|
* @return array |
|
337
|
|
|
*/ |
|
338
|
|
|
private static function getJWTLoaderConfiguration($name, $verifier, $checker, $decrypter = null, $is_public = true) |
|
339
|
|
|
{ |
|
340
|
|
|
self::checkParameters($name, $is_public); |
|
341
|
|
|
Assertion::string($verifier); |
|
342
|
|
|
Assertion::notEmpty($verifier); |
|
343
|
|
|
Assertion::string($checker); |
|
344
|
|
|
Assertion::notEmpty($checker); |
|
345
|
|
|
Assertion::nullOrString($decrypter); |
|
346
|
|
|
|
|
347
|
|
|
return [ |
|
348
|
|
|
self::BUNDLE_ALIAS => [ |
|
349
|
|
|
'jwt_loaders' => [ |
|
350
|
|
|
$name => [ |
|
351
|
|
|
'is_public' => $is_public, |
|
352
|
|
|
'verifier' => $verifier, |
|
353
|
|
|
'checker' => $checker, |
|
354
|
|
|
'decrypter' => $decrypter, |
|
355
|
|
|
], |
|
356
|
|
|
], |
|
357
|
|
|
], |
|
358
|
|
|
]; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* @param string $name |
|
363
|
|
|
* @param string $storage_path |
|
364
|
|
|
* @param int $nb_keys |
|
365
|
|
|
* @param array $key_configuration |
|
366
|
|
|
* @param bool $is_rotatable |
|
367
|
|
|
* @param bool $is_public |
|
368
|
|
|
* |
|
369
|
|
|
* @return array |
|
370
|
|
|
*/ |
|
371
|
|
|
private static function getRandomJWKSetConfiguration($name, $storage_path, $nb_keys, array $key_configuration, $is_rotatable = false, $is_public = true) |
|
372
|
|
|
{ |
|
373
|
|
|
self::checkParameters($name, $is_public); |
|
374
|
|
|
Assertion::string($storage_path); |
|
375
|
|
|
Assertion::notEmpty($storage_path); |
|
376
|
|
|
Assertion::integer($nb_keys); |
|
377
|
|
|
Assertion::greaterThan($nb_keys, 0); |
|
378
|
|
|
Assertion::boolean($is_rotatable); |
|
379
|
|
|
|
|
380
|
|
|
return [ |
|
381
|
|
|
self::BUNDLE_ALIAS => [ |
|
382
|
|
|
'key_sets' => [ |
|
383
|
|
|
$name => [ |
|
384
|
|
|
'auto' => [ |
|
385
|
|
|
'is_rotatable' => $is_rotatable, |
|
386
|
|
|
'is_public' => $is_public, |
|
387
|
|
|
'nb_keys' => $nb_keys, |
|
388
|
|
|
'key_configuration' => $key_configuration, |
|
389
|
|
|
'storage_path' => $storage_path, |
|
390
|
|
|
], |
|
391
|
|
|
], |
|
392
|
|
|
], |
|
393
|
|
|
], |
|
394
|
|
|
]; |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
/** |
|
398
|
|
|
* @param string $name |
|
399
|
|
|
* @param string $jwkset |
|
400
|
|
|
* @param bool $is_public |
|
401
|
|
|
* |
|
402
|
|
|
* @return array |
|
403
|
|
|
*/ |
|
404
|
|
|
private static function getPublicJWKSetConfiguration($name, $jwkset, $is_public = true) |
|
405
|
|
|
{ |
|
406
|
|
|
self::checkParameters($name, $is_public); |
|
407
|
|
|
Assertion::string($jwkset); |
|
408
|
|
|
Assertion::notEmpty($jwkset); |
|
409
|
|
|
|
|
410
|
|
|
return [ |
|
411
|
|
|
self::BUNDLE_ALIAS => [ |
|
412
|
|
|
'key_sets' => [ |
|
413
|
|
|
$name => [ |
|
414
|
|
|
'public_jwkset' => [ |
|
415
|
|
|
'is_public' => $is_public, |
|
416
|
|
|
'id' => $jwkset, |
|
417
|
|
|
], |
|
418
|
|
|
], |
|
419
|
|
|
], |
|
420
|
|
|
], |
|
421
|
|
|
]; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* @param string $name |
|
426
|
|
|
* @param string[] $jwksets |
|
427
|
|
|
* @param bool $is_public |
|
428
|
|
|
* |
|
429
|
|
|
* @return array |
|
430
|
|
|
*/ |
|
431
|
|
|
private static function getJWKSetsConfiguration($name, array $jwksets, $is_public = true) |
|
432
|
|
|
{ |
|
433
|
|
|
self::checkParameters($name, $is_public); |
|
434
|
|
|
Assertion::isArray($jwksets); |
|
435
|
|
|
Assertion::allString($jwksets); |
|
436
|
|
|
Assertion::allNotEmpty($jwksets); |
|
437
|
|
|
|
|
438
|
|
|
return [ |
|
439
|
|
|
self::BUNDLE_ALIAS => [ |
|
440
|
|
|
'key_sets' => [ |
|
441
|
|
|
$name => [ |
|
442
|
|
|
'jwksets' => [ |
|
443
|
|
|
'is_public' => $is_public, |
|
444
|
|
|
'id' => $jwksets, |
|
445
|
|
|
], |
|
446
|
|
|
], |
|
447
|
|
|
], |
|
448
|
|
|
], |
|
449
|
|
|
]; |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* @param string $name |
|
454
|
|
|
* @param bool $is_public |
|
455
|
|
|
*/ |
|
456
|
|
|
private static function checkParameters($name, $is_public) |
|
457
|
|
|
{ |
|
458
|
|
|
Assertion::string($name); |
|
459
|
|
|
Assertion::notEmpty($name); |
|
460
|
|
|
Assertion::boolean($is_public); |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
465
|
|
|
* @param array $config |
|
466
|
|
|
* @param string $element |
|
467
|
|
|
*/ |
|
468
|
|
|
private static function updateJoseConfiguration(ContainerBuilder $container, array $config, $element) |
|
469
|
|
|
{ |
|
470
|
|
|
self::checkJoseBundleEnabled($container); |
|
471
|
|
|
$jose_config = current($container->getExtensionConfig(self::BUNDLE_ALIAS)); |
|
472
|
|
|
if (!isset($jose_config[$element])) { |
|
473
|
|
|
$jose_config[$element] = []; |
|
474
|
|
|
} |
|
475
|
|
|
$jose_config[$element] = array_merge($jose_config[$element], $config[self::BUNDLE_ALIAS][$element]); |
|
476
|
|
|
$container->prependExtensionConfig(self::BUNDLE_ALIAS, $jose_config); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
/** |
|
480
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
481
|
|
|
* |
|
482
|
|
|
* @throws \InvalidArgumentException |
|
483
|
|
|
*/ |
|
484
|
|
|
private static function checkJoseBundleEnabled(ContainerBuilder $container) |
|
485
|
|
|
{ |
|
486
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
|
487
|
|
|
Assertion::keyExists($bundles, 'SpomkyLabsJoseBundle', 'The "Spomky-Labs/JoseBundle" must be enabled.'); |
|
488
|
|
|
|
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
|