1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 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 OAuth2Framework\Bundle\DependencyInjection\Component\Endpoint\Metadata; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
18
|
|
|
use Symfony\Component\Config\FileLocator; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
21
|
|
|
|
22
|
|
|
class MetadataEndpointSource implements Component |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var Component[] |
26
|
|
|
*/ |
27
|
|
|
private $subComponents = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* MetadataEndpointSource constructor. |
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
$this->subComponents = [ |
35
|
|
|
new SignatureSource(), |
36
|
|
|
new CustomRouteSource(), |
37
|
|
|
new CustomValuesSource(), |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function name(): string |
45
|
|
|
{ |
46
|
|
|
return 'metadata'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function load(array $configs, ContainerBuilder $container) |
53
|
|
|
{ |
54
|
|
|
if (!$configs['endpoint']['metadata']['enabled']) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
$container->setParameter('oauth2_server.endpoint.metadata.path', $configs['endpoint']['metadata']['path']); |
58
|
|
|
|
59
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../../Resources/config/endpoint/metadata')); |
|
|
|
|
60
|
|
|
//$loader->load('metadata.php'); |
|
|
|
|
61
|
|
|
|
62
|
|
|
foreach ($this->subComponents as $subComponent) { |
63
|
|
|
$subComponent->load($configs, $container); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
71
|
|
|
{ |
72
|
|
|
$childNode = $node->children() |
73
|
|
|
->arrayNode($this->name()) |
74
|
|
|
->addDefaultsIfNotSet() |
75
|
|
|
->canBeEnabled(); |
76
|
|
|
|
77
|
|
|
$childNode->children() |
78
|
|
|
->scalarNode('path') |
79
|
|
|
->defaultValue('/.well-known/openid-configuration') |
80
|
|
|
->end() |
81
|
|
|
->end(); |
82
|
|
|
|
83
|
|
|
foreach ($this->subComponents as $subComponent) { |
84
|
|
|
$subComponent->getNodeDefinition($childNode); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
92
|
|
|
{ |
93
|
|
|
$updatedConfig = []; |
94
|
|
|
foreach ($this->subComponents as $subComponent) { |
95
|
|
|
$updatedConfig = array_merge( |
96
|
|
|
$updatedConfig, |
97
|
|
|
$subComponent->prepend($container, $config) |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $updatedConfig; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.