Failed Conditions
Push — ng ( 57a3a2...d2fe45 )
by Florent
03:39
created

ClientCredentialsSource::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
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\Grant\ClientCredentials;
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
final class ClientCredentialsSource implements Component
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function name(): string
28
    {
29
        return 'client_credentials';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function load(array $configs, ContainerBuilder $container)
36
    {
37
        if ($configs['grant']['client_credentials']['enabled']) {
38
            $container->setParameter('oauth2_server.grant.client_credentials.issue_refresh_token', $configs['grant']['client_credentials']['issue_refresh_token']);
39
            $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../../Resources/config/grant'));
40
            $loader->load('client_credentials.php');
41
        }
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getNodeDefinition(NodeDefinition $node)
48
    {
49
        $node->children()
50
            ->arrayNode('client_credentials')
51
                ->canBeEnabled()
52
                ->children()
53
                    ->booleanNode('issue_refresh_token')
54
                        ->info('If enabled, a refresh token will be issued with an access token (not recommended)')
55
                        ->defaultFalse()
56
                    ->end()
57
                ->end()
58
            ->end()
59
        ->end();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function prepend(ContainerBuilder $container, array $config): array
66
    {
67
        //Nothing to do
68
        return [];
69
    }
70
}
71