Failed Conditions
Push — v7 ( 79e5af...524357 )
by Florent
02:58
created

AlgorithmCompilerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2017 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 Jose\Bundle\Core\DependencyInjection\Compiler;
13
14
use Jose\Component\Core\JWAManagerFactory;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class AlgorithmCompilerPass implements CompilerPassInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function process(ContainerBuilder $container)
25
    {
26
        if (!$container->hasDefinition(JWAManagerFactory::class)) {
27
            return;
28
        }
29
30
        $definition = $container->getDefinition(JWAManagerFactory::class);
31
32
        $taggedAlgorithmServices = $container->findTaggedServiceIds('jose.algorithm');
33
        foreach ($taggedAlgorithmServices as $id => $tags) {
34
            foreach ($tags as $attributes) {
35
                if (!array_key_exists('alias', $attributes)) {
36
                    throw new \InvalidArgumentException(sprintf("The algorithm '%s' does not have any 'alias' attribute.", $id));
37
                }
38
                $definition->addMethodCall('add', [$attributes['alias'], new Reference($id)]);
39
            }
40
        }
41
    }
42
}
43