Failed Conditions
Pull Request — master (#47)
by Florent
04:28
created

CoreSource::getCompilerPasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
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\DependencyInjection\Source\Core;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler;
17
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
18
use Jose\Component\Core\Converter\JsonConverter;
19
use Jose\Component\Core\Converter\StandardConverter;
20
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
21
use Symfony\Component\Config\FileLocator;
22
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
25
26
/**
27
 * Class CoreSource.
28
 */
29
final class CoreSource implements Source
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function name(): string
35
    {
36
        return 'core';
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function load(array $config, ContainerBuilder $container)
43
    {
44
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
45
        $loader->load('services.yml');
46
47
        if (true === $container->getParameter('kernel.debug')) {
48
            $loader->load('dev_services.yml');
49
        }
50
51
        $container->setAlias(JsonConverter::class, $config['json_converter']);
52
        if (StandardConverter::class === $config['json_converter']) {
53
            $loader->load('json_converter.yml');
54
        }
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getNodeDefinition(ArrayNodeDefinition $node)
61
    {
62
        $node
63
            ->children()
64
                ->scalarNode('json_converter')
65
                    ->defaultValue(StandardConverter::class)
66
                    ->info('Converter used to encode and decode JSON objects (JWT payloads, keys, key sets...).')
67
                ->end()
68
            ->end();
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function prepend(ContainerBuilder $container, array $config): array
75
    {
76
        return [];
77
    }
78
79
    /**
80
     * @return CompilerPassInterface[]
81
     */
82
    public function getCompilerPasses(): array
83
    {
84
        return [
85
            new Compiler\AlgorithmCompilerPass(),
86
            new Compiler\DataCollectorCompilerPass(),
87
            new Compiler\CheckerCollectorCompilerPass(),
88
            new Compiler\KeyCollectorCompilerPass(),
89
            new Compiler\JWSCollectorCompilerPass(),
90
            new Compiler\JWECollectorCompilerPass(),
91
        ];
92
    }
93
}
94