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\Component\Endpoint\Metadata; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\Component\Component; |
17
|
|
|
use OAuth2Framework\Bundle\Component\ComponentWithCompilerPasses; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
19
|
|
|
use Symfony\Component\Config\FileLocator; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
22
|
|
|
|
23
|
|
|
class MetadataEndpointSource implements Component |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Component[] |
27
|
|
|
*/ |
28
|
|
|
private $subComponents = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* MetadataEndpointSource constructor. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
$this->subComponents = [ |
36
|
|
|
new SignatureSource(), |
37
|
|
|
new CustomRouteSource(), |
38
|
|
|
new CustomValuesSource(), |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function name(): string |
46
|
|
|
{ |
47
|
|
|
return 'metadata'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function load(array $configs, ContainerBuilder $container) |
54
|
|
|
{ |
55
|
|
|
if (!$configs['endpoint']['metadata']['enabled']) { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
$container->setParameter('oauth2_server.endpoint.metadata.path', $configs['endpoint']['metadata']['path']); |
59
|
|
|
|
60
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/metadata')); |
|
|
|
|
61
|
|
|
//$loader->load('metadata.php'); |
|
|
|
|
62
|
|
|
|
63
|
|
|
foreach ($this->subComponents as $subComponent) { |
64
|
|
|
$subComponent->load($configs, $container); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
72
|
|
|
{ |
73
|
|
|
$childNode = $node->children() |
74
|
|
|
->arrayNode($this->name()) |
75
|
|
|
->addDefaultsIfNotSet() |
76
|
|
|
->canBeEnabled(); |
77
|
|
|
|
78
|
|
|
$childNode->children() |
79
|
|
|
->scalarNode('path') |
80
|
|
|
->defaultValue('/.well-known/openid-configuration') |
81
|
|
|
->end() |
82
|
|
|
->end(); |
83
|
|
|
|
84
|
|
|
foreach ($this->subComponents as $subComponent) { |
85
|
|
|
$subComponent->getNodeDefinition($childNode); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
93
|
|
|
{ |
94
|
|
|
$updatedConfig = []; |
95
|
|
|
foreach ($this->subComponents as $subComponent) { |
96
|
|
|
$updatedConfig = array_merge( |
97
|
|
|
$updatedConfig, |
98
|
|
|
$subComponent->prepend($container, $config) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $updatedConfig; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function build(ContainerBuilder $container) |
109
|
|
|
{ |
110
|
|
|
//Nothing to do |
111
|
|
|
foreach ($this->subComponents as $component) { |
112
|
|
|
$component->build($container); |
113
|
|
|
}; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
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.