Failed Conditions
Push — master ( 7202e9...38ed0d )
by Florent
02:32
created

JoseFrameworkBundle::addCompilerPassIfExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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 Jose\Bundle\JoseFramework;
15
16
use Jose\Bundle\Checker\DependencyInjection\Compiler\ClaimCheckerCompilerPass;
17
use Jose\Bundle\Checker\DependencyInjection\Compiler\HeaderCheckerCompilerPass;
18
use Jose\Bundle\Console\DependencyInjection\Compiler\KeyAnalyzerCompilerPass;
19
use Jose\Bundle\Encryption\DependencyInjection\Compiler\CompressionMethodCompilerPass;
20
use Jose\Bundle\Encryption\DependencyInjection\Compiler\SerializerCompilerPass as EncryptionSerializerCompilerPass;
21
use Jose\Bundle\Signature\DependencyInjection\Compiler\SerializerCompilerPass as SignatureSerializerCompilerPass;
22
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\AlgorithmCompilerPass;
23
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\CheckerCollectorCompilerPass;
24
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\DataCollectorCompilerPass;
25
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\JWECollectorCompilerPass;
26
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\JWSCollectorCompilerPass;
27
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\KeyCollectorCompilerPass;
28
use Jose\Bundle\JoseFramework\DependencyInjection\JoseFrameworkExtension;
29
use Jose\Bundle\KeyManagement\DependencyInjection\Compiler\KeySetControllerCompilerPass;
30
use Symfony\Component\Config\Resource\ClassExistenceResource;
31
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
32
use Symfony\Component\DependencyInjection\ContainerBuilder;
33
use Symfony\Component\HttpKernel\Bundle\Bundle;
34
35
/**
36
 * Class JoseFrameworkBundle.
37
 */
38
final class JoseFrameworkBundle extends Bundle
39
{
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getContainerExtension()
44
    {
45
        return new JoseFrameworkExtension('jose');
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function build(ContainerBuilder $container)
52
    {
53
        parent::build($container);
54
        $container->addCompilerPass(new DataCollectorCompilerPass());
55
        $container->addCompilerPass(new JWSCollectorCompilerPass());
56
        $container->addCompilerPass(new JWECollectorCompilerPass());
57
        $container->addCompilerPass(new KeyCollectorCompilerPass());
58
        $container->addCompilerPass(new CheckerCollectorCompilerPass());
59
        $container->addCompilerPass(new AlgorithmCompilerPass());
60
61
        $this->addCompilerPassIfExists($container, ClaimCheckerCompilerPass::class);
62
        $this->addCompilerPassIfExists($container, HeaderCheckerCompilerPass::class);
63
        $this->addCompilerPassIfExists($container, KeyAnalyzerCompilerPass::class);
64
        $this->addCompilerPassIfExists($container, CompressionMethodCompilerPass::class);
65
        $this->addCompilerPassIfExists($container, EncryptionSerializerCompilerPass::class);
66
        $this->addCompilerPassIfExists($container, KeySetControllerCompilerPass::class);
67
        $this->addCompilerPassIfExists($container, SignatureSerializerCompilerPass::class);
68
    }
69
70
    private function addCompilerPassIfExists(ContainerBuilder $container, $class, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0)
71
    {
72
        $container->addResource(new ClassExistenceResource($class));
73
        if (class_exists($class)) {
74
            $container->addCompilerPass(new $class(), $type, $priority);
75
        }
76
    }
77
}
78