1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\KeyManagement\DependencyInjection\Source; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source; |
17
|
|
|
use Jose\Bundle\KeyManagement\DependencyInjection\Source\JWKSetSource\JWKSetSource as JWKSetSourceInterface; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
19
|
|
|
use Symfony\Component\Config\FileLocator; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class JWKSetSource. |
25
|
|
|
*/ |
26
|
|
|
final class JWKSetSource implements Source |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var null|JWKSetSourceInterface[] |
30
|
|
|
*/ |
31
|
|
|
private $jwkset_sources = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function name(): string |
37
|
|
|
{ |
38
|
|
|
return 'key_sets'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function load(array $configs, ContainerBuilder $container) |
45
|
|
|
{ |
46
|
|
|
$sources = $this->getJWKSetSources(); |
47
|
|
|
foreach ($configs[$this->name()] as $name => $itemConfig) { |
48
|
|
|
foreach ($itemConfig as $sourceName => $sourceConfig) { |
49
|
|
|
if (array_key_exists($sourceName, $sources)) { |
50
|
|
|
$source = $sources[$sourceName]; |
51
|
|
|
$source->create($container, 'key_set', $name, $sourceConfig); |
|
|
|
|
52
|
|
|
} else { |
53
|
|
|
throw new \LogicException(sprintf('The JWKSet definition "%s" is not configured.', $name)); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node) |
63
|
|
|
{ |
64
|
|
|
$sourceNodeBuilder = $node |
|
|
|
|
65
|
|
|
->children() |
66
|
|
|
->arrayNode('key_sets') |
67
|
|
|
->useAttributeAsKey('name') |
68
|
|
|
->prototype('array') |
69
|
|
|
->performNoDeepMerging() |
70
|
|
|
->children(); |
71
|
|
|
foreach ($this->getJWKSetSources() as $name => $source) { |
72
|
|
|
$sourceNode = $sourceNodeBuilder->arrayNode($name)->canBeUnset(); |
73
|
|
|
$source->addConfiguration($sourceNode); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function prepend(ContainerBuilder $container, array $config): ?array |
81
|
|
|
{ |
82
|
|
|
return null; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return JWKSetSource[] |
87
|
|
|
*/ |
88
|
|
|
private function getJWKSetSources(): array |
89
|
|
|
{ |
90
|
|
|
if (null !== $this->jwkset_sources) { |
91
|
|
|
return $this->jwkset_sources; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// load bundled adapter factories |
95
|
|
|
$tempContainer = new ContainerBuilder(); |
96
|
|
|
$loader = new YamlFileLoader($tempContainer, new FileLocator(__DIR__.'/../../Resources/config')); |
97
|
|
|
$loader->load('jwkset_sources.yml'); |
98
|
|
|
|
99
|
|
|
$services = $tempContainer->findTaggedServiceIds('jose.jwkset_source'); |
100
|
|
|
$jwkset_sources = []; |
101
|
|
|
foreach (array_keys($services) as $id) { |
102
|
|
|
$factory = $tempContainer->get($id); |
103
|
|
|
$jwkset_sources[str_replace('-', '_', $factory->getKeySet())] = $factory; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->jwkset_sources = $jwkset_sources; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.