Failed Conditions
Push — ng ( c00098...4b490a )
by Florent
06:57
created

EndpointSource::getNodeDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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;
15
16
use OAuth2Framework\Bundle\Component\Component;
17
use OAuth2Framework\Bundle\Component\ComponentWithCompilerPasses;
18
use OAuth2Framework\Bundle\Component\Endpoint\ClientConfiguration\ClientConfigurationSource;
19
use OAuth2Framework\Bundle\Component\Endpoint\ClientRegistration\ClientRegistrationSource;
20
use OAuth2Framework\Bundle\Component\Endpoint\IssuerDiscovery\IssuerDiscoveryEndpointSource;
21
use OAuth2Framework\Bundle\Component\Endpoint\JwksUri\JwksUriEndpointSource;
22
use OAuth2Framework\Bundle\Component\Endpoint\Metadata\MetadataEndpointSource;
23
use OAuth2Framework\Bundle\Component\Endpoint\SessionManagement\SessionManagementEndpointSource;
24
use OAuth2Framework\Bundle\Component\Endpoint\Token\TokenEndpointSource;
25
use OAuth2Framework\Bundle\Component\Endpoint\TokenIntrospection\TokenIntrospectionEndpointSource;
26
use OAuth2Framework\Bundle\Component\Endpoint\TokenRevocation\TokenRevocationEndpointSource;
27
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
28
use Symfony\Component\DependencyInjection\ContainerBuilder;
29
30
class EndpointSource implements Component
31
{
32
    /**
33
     * @var Component[]
34
     */
35
    private $subComponents = [];
36
37
    /**
38
     * EndpointSource constructor.
39
     */
40
    public function __construct()
41
    {
42
        $this->subComponents = [
43
            new ClientRegistrationSource(),
44
            new ClientConfigurationSource(),
45
            new TokenEndpointSource(),
46
            new TokenIntrospectionEndpointSource(),
47
            new TokenRevocationEndpointSource(),
48
            new JwksUriEndpointSource(),
49
            new MetadataEndpointSource(),
50
            new IssuerDiscoveryEndpointSource(),
51
            new SessionManagementEndpointSource(),
52
        ];
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function name(): string
59
    {
60
        return 'endpoint';
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function load(array $configs, ContainerBuilder $container)
67
    {
68
        foreach ($this->subComponents as $subComponent) {
69
            $subComponent->load($configs, $container);
70
        }
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getNodeDefinition(NodeDefinition $node)
77
    {
78
        $childNode = $node->children()
79
            ->arrayNode($this->name())
80
                ->addDefaultsIfNotSet();
81
82
        foreach ($this->subComponents as $subComponent) {
83
            $subComponent->getNodeDefinition($childNode);
84
        }
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function prepend(ContainerBuilder $container, array $config): array
91
    {
92
        $updatedConfig = [];
93
        foreach ($this->subComponents as $subComponent) {
94
            $updatedConfig = array_merge(
95
                $updatedConfig,
96
                $subComponent->prepend($container, $config)
97
            );
98
        }
99
100
        return $updatedConfig;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function build(ContainerBuilder $container)
107
    {
108
        foreach ($this->subComponents as $component) {
109
            $component->build($container);
110
        };
111
    }
112
}
113