CushonHealthExtension::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cushon\HealthBundle\DependencyInjection;
6
7
use Cushon\HealthBundle\ApplicationHealth\DependencyCheck;
8
use Cushon\HealthBundle\CushonHealthBundle;
9
use Cushon\HealthBundle\Traits\BundleRootKeyTrait;
10
use Symfony\Component\Config\FileLocator;
11
use Symfony\Component\Config\Loader\FileLoader;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Extension\Extension;
14
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
15
16
final class CushonHealthExtension extends Extension
17
{
18
    use BundleRootKeyTrait;
19
20
    public const KEY_DEPENDENCY_CHECKS = 'dependency_check';
21
22
    /** @var FileLocator  */
23
    private FileLocator $fileLocator;
24
25
    /**
26
     * @param FileLocator $fileLocator
27
     * @param string $rootKey
28
     */
29
    public function __construct(
30
        FileLocator $fileLocator,
31
        string $rootKey = CushonHealthBundle::BUNDLE_ROOT_KEY
32
    ) {
33
        $this->fileLocator = $fileLocator;
34
        $this->rootKey = $rootKey;
35
    }
36
37
    /**
38
     * @param mixed[] $configs
39
     * @param ContainerBuilder $container
40
     * @throws \Exception
41
     * @SuppressWarnings(PHPMD.UnusedFormalParameter) Comes from the Symfony parent
42
     */
43
    public function load(array $configs, ContainerBuilder $container): void
44
    {
45
        $this->createLoader($container)->load('services.yaml');
46
        $dependencyCheckTag = $this->generateKeyFromRoot(self::KEY_DEPENDENCY_CHECKS);
47
48
        $container->registerForAutoconfiguration(DependencyCheck::class)
49
            ->addTag($dependencyCheckTag);
50
    }
51
52
    /**
53
     * @param ContainerBuilder $container
54
     * @return FileLoader
55
     */
56
    private function createLoader(ContainerBuilder $container): FileLoader
57
    {
58
        return new YamlFileLoader($container, $this->fileLocator);
59
    }
60
}
61