Completed
Push — master ( e35344...c8833b )
by Alexandru
21:49
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 34
nc 1
nop 0
1
<?php // @codingStandardsIgnoreFile
2
3
namespace Arki\RequestId\Integrations\Symfony\DependencyInjection;
4
5
use Arki\RequestId\RequestId;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
final class Configuration implements ConfigurationInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $alias;
15
16
    /**
17
     * @param string $alias
18
     */
19
    public function __construct($alias)
20
    {
21
        $this->alias = $alias;
22
    }
23
24
    /**
25
     * Generates the configuration tree builder.
26
     *
27
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
28
     */
29
    public function getConfigTreeBuilder()
30
    {
31
        $tree = new TreeBuilder();
32
        $root = $tree->root($this->alias);
33
        $root
34
            ->children()
35
                ->scalarNode('request_header')
36
                    ->cannotBeEmpty()
37
                    ->defaultValue(RequestId::HEADER_NAME)
38
                    ->info('The header in which the bundle will look for and set request IDs')
39
                ->end()
40
            ->booleanNode('trust_request_header')
41
            ->defaultValue(true)
42
            ->info("Whether or not to trust the incoming request's `Request-Id` header as a real ID")
43
            ->end()
44
            ->scalarNode('response_header')
45
            ->cannotBeEmpty()
46
            ->defaultValue('Request-Id')
47
            ->info('The header the bundle will set the request ID at in the response')
48
            ->end()
49
            ->scalarNode('storage_service')
50
            ->info('The service name for request ID storage. Defaults to `SimpleIdStorage`')
51
            ->end()
52
            ->scalarNode('generator_service')
53
            ->info('The service name for the request ID generator. Defaults to `Uuid4IdGenerator`')
54
            ->end()
55
            ->booleanNode('enable_monolog')
56
            ->info('Whether or not to turn on the request ID processor for monolog')
57
            ->defaultTrue()
58
            ->end()
59
            ->booleanNode('enable_twig')
60
            ->info('Whether or not to enable the twig `request_id()` function. Only works if TwigBundle is present.')
61
            ->defaultTrue()
62
            ->end();
63
64
        return $tree;
65
    }
66
}
67
68