Completed
Pull Request — master (#7)
by John
02:22
created

KleijnWebJwtExtension::load()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 3
eloc 15
nc 3
nop 2
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\JwtBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\JwtBundle\DependencyInjection;
10
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\Config\FileLocator;
13
use Symfony\Component\DependencyInjection\Definition;
14
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15
use Symfony\Component\DependencyInjection\Loader;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * @author John Kleijn <[email protected]>
20
 */
21
class KleijnWebJwtExtension extends Extension
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function load(array $configs, ContainerBuilder $container)
27
    {
28
        $config = $this->processConfiguration(new Configuration(), $configs);
29
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
30
        $loader->load('services.yml');
31
32
        $keysDefinition = new Definition('jwt.keys');
33
        $keysDefinition->setClass('ArrayObject');
34
35
        foreach ($config['keys'] as $keyId => $keyConfig) {
36
37
            $keyConfig['kid'] = $keyId;
38
            $keyDefinition    = new Definition('jwt.keys.' . $keyId);
39
            $keyDefinition->setClass('KleijnWeb\JwtBundle\Authenticator\JwtKey');
40
41
            if (isset($keyConfig['loader'])) {
42
                $keyConfig['loader'] = new Reference($keyConfig['loader']);
43
            }
44
            $keyDefinition->addArgument($keyConfig);
45
            $keysDefinition->addMethodCall('append', [$keyDefinition]);
46
        }
47
48
        $container->getDefinition('jwt.authenticator')->addArgument($keysDefinition);
49
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getAlias()
56
    {
57
        return "jwt";
58
    }
59
}
60