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\DependencyInjection\Source; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
18
|
|
|
|
19
|
|
|
final class CheckerSource implements SourceInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function getName() |
25
|
|
|
{ |
26
|
|
|
return 'checkers'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function createService($name, array $config, ContainerBuilder $container) |
33
|
|
|
{ |
34
|
|
|
$service_id = sprintf('jose.checker.%s', $name); |
35
|
|
|
$definition = new Definition('Jose\Checker\CheckerManager'); |
36
|
|
|
$definition->setFactory([ |
37
|
|
|
new Reference('jose.factory.service'), |
38
|
|
|
'createChecker', |
39
|
|
|
]); |
40
|
|
|
$definition->setArguments([ |
41
|
|
|
$config['claims'], |
42
|
|
|
$config['headers'], |
43
|
|
|
]); |
44
|
|
|
$definition->setPublic($config['is_public']); |
45
|
|
|
|
46
|
|
|
$container->setDefinition($service_id, $definition); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node) |
53
|
|
|
{ |
54
|
|
|
$node |
55
|
|
|
->children() |
56
|
|
|
->arrayNode($this->getName()) |
57
|
|
|
->useAttributeAsKey('name') |
58
|
|
|
->prototype('array') |
59
|
|
|
->children() |
60
|
|
|
->booleanNode('is_public') |
61
|
|
|
->info('If true, the service will be public, else private.') |
62
|
|
|
->defaultTrue() |
63
|
|
|
->end() |
64
|
|
|
->arrayNode('claims') |
65
|
|
|
->useAttributeAsKey('name') |
66
|
|
|
->isRequired() |
67
|
|
|
->prototype('scalar')->end() |
68
|
|
|
->end() |
69
|
|
|
->arrayNode('headers') |
70
|
|
|
->useAttributeAsKey('name') |
71
|
|
|
->isRequired() |
72
|
|
|
->prototype('scalar')->end() |
73
|
|
|
->end() |
74
|
|
|
->end() |
75
|
|
|
->end() |
76
|
|
|
->end() |
77
|
|
|
->end(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function prepend(ContainerBuilder $container, array $config) |
84
|
|
|
{ |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|