Failed Conditions
Push — ng ( e90992...13fb6e )
by Florent
17:32
created

getNodeDefinition()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 32
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 28
nc 1
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\DependencyInjection\Component\Endpoint;
15
16
use Fluent\PhpConfigFileLoader;
17
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
22
final class SessionManagementEndpointSource implements Component
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: load, prepend
Loading history...
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function continueLoading(string $path, ContainerBuilder $container, array $config)
28
    {
29
        foreach (['path', 'storage_name', 'template'] as $key) {
30
            $container->setParameter($path.'.'.$key, $config[$key]);
31
        }
32
        $loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint'));
33
        $loader->load('session_management.php');
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function name(): string
40
    {
41
        return 'session_management';
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getNodeDefinition(NodeDefinition $node)
48
    {
49
50
        $node
51
            ->validate()
52
                ->ifTrue(function ($config) {
53
                    return true === $config['enabled'] && empty($config['path']);
54
                })
55
                ->thenInvalid('The route name must be set.')
56
            ->end()
57
            ->validate()
58
                ->ifTrue(function ($config) {
59
                    return true === $config['enabled'] && empty($config['storage_name']);
60
                })->thenInvalid('The option "storage_name" must be set.')
61
            ->end()
62
            ->validate()
63
                ->ifTrue(function ($config) {
64
                    return true === $config['enabled'] && empty($config['template']);
65
                })->thenInvalid('The option "template" must be set.')
66
            ->end()
67
            ->children()
68
                ->scalarNode('path')
69
                ->end()
70
                ->scalarNode('storage_name')
71
                    ->defaultValue('oidc_browser_state')
72
                ->end()
73
                ->scalarNode('template')
74
                    ->info('The template of the OP iframe.')
75
                    ->defaultValue('@OAuth2FrameworkBundle/iframe/iframe.html.twig')
76
                ->end()
77
            ->end();
78
    }
79
}
80