Completed
Pull Request — master (#24)
by Florent
02:31
created

X5U::createDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 11
nop 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource;
13
14
use SpomkyLabs\JoseBundle\DependencyInjection\Source\AbstractSource;
15
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Definition;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
class X5U extends AbstractSource implements JWKSetSourceInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function createDefinition(ContainerBuilder $container, array $config)
26
    {
27
        $definition = new Definition('Jose\Object\JWKSet');
28
        $definition->setFactory([
29
            new Reference('jose.factory.jwk'),
30
            'createFromX5U',
31
        ]);
32
        $definition->setArguments([
33
            $config['url'],
34
            $config['is_secured'],
35
            $config['cache'],
36
            $config['cache_ttl'],
37
        ]);
38
39
        return $definition;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getKeySet()
46
    {
47
        return 'x5u';
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function addConfiguration(NodeDefinition $node)
54
    {
55
        parent::addConfiguration($node);
56
        $node
57
            ->children()
58
                ->scalarNode('url')->isRequired()->end()
59
                ->booleanNode('is_secured')->defaultTrue()->end()
60
                ->scalarNode('cache')->defaultNull()->end()
61
                ->integerNode('cache_ttl')->defaultValue(0)->end()
62
            ->end();
63
    }
64
}
65