ConfigUtil::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lendable\DoctrineExtensionsBundle\Util;
6
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
10
/**
11
 * Stores and fetches configuration via an abstract service in the container.
12
 *
13
 * This service will be cleaned up during the late phase of container optimization.
14
 */
15
final class ConfigUtil
16
{
17
    const SERVICE_ID = 'lendable_doctrine_extensions_config';
18
19
    /**
20
     * @codeCoverageIgnore
21
     */
22
    private function __construct()
23
    {
24
    }
25
26
    /**
27
     * Fetches bundle configuration from the container.
28
     *
29
     * @param ContainerBuilder $containerBuilder
30
     *
31
     * @return array
32
     */
33
    public static function fetch(ContainerBuilder $containerBuilder): array
34
    {
35
        return $containerBuilder->getDefinition(self::SERVICE_ID)->getArgument(0);
36
    }
37
38
    /**
39
     * Stores bundle configuration in the container temporarily.
40
     *
41
     * @param ContainerBuilder $containerBuilder
42
     * @param array $config
43
     */
44
    public static function store(ContainerBuilder $containerBuilder, array $config)
45
    {
46
        $definition = new Definition(\stdClass::class, [$config]);
47
        $definition->setAbstract(true);
48
49
        $containerBuilder->setDefinition(self::SERVICE_ID, $definition);
50
    }
51
}
52