Completed
Push — master ( 24b9f5...f17bc4 )
by Florent
02:53
created

CompressionCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 3 Features 0
Metric Value
c 7
b 3
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 11
nc 4
nop 1
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\Compiler;
13
14
use Assert\Assertion;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class CompressionCompilerPass implements CompilerPassInterface
20
{
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->hasDefinition('jose.compression_manager')) {
24
            return;
25
        }
26
27
        $loaded = [];
28
        $definition = $container->getDefinition('jose.compression_manager');
29
30
        $taggedServices = $container->findTaggedServiceIds('jose_compression');
31
        foreach ($taggedServices as $id => $tags) {
32
            foreach ($tags as $attributes) {
33
                Assertion::keyExists($attributes, 'alias', sprintf("The compression method '%s' does not have any 'alias' attribute.", $id));
34
                $loaded[] = $attributes['alias'];
35
                $definition->addMethodCall('addCompressionAlgorithm', [new Reference($id)]);
36
            }
37
        }
38
    }
39
}
40