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

ClientRegistrationSource::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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\ClientRegistration;
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 ClientRegistrationSource implements Component
24
{
25
    /**
26
     * @var Component[]
27
     */
28
    private $subComponents = [];
29
30
    /**
31
     * EndpointSource constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->subComponents = [
36
            new InitialAccessTokenSource(),
37
            new SoftwareStatementSource(),
38
        ];
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function name(): string
45
    {
46
        return 'client_registration';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function load(array $configs, ContainerBuilder $container)
53
    {
54
        if (!$configs['endpoint']['client_registration']['enabled']) {
55
            return;
56
        }
57
        $container->setParameter('oauth2_server.endpoint.client_registration.path', $configs['endpoint']['client_registration']['path']);
58
59
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/client_registration'));
60
        $loader->load('client_registration.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('/client/management')
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
    /**
105
     * {@inheritdoc}
106
     */
107
    public function build(ContainerBuilder $container)
108
    {
109
        foreach ($this->subComponents as $component) {
110
            $component->build($container);
111
        };
112
    }
113
}
114