EmailEngineConfiguration::addTemplatesSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace SfCod\EmailEngineBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * Class EmailEngineConfiguration
11
 *
12
 * @author Virchenko Maksim <[email protected]>
13
 *
14
 * @package SfCod\EmailEngineBundle\DependencyInjection
15
 */
16
class EmailEngineConfiguration implements ConfigurationInterface
17
{
18
    /**
19
     * Generates the configuration tree builder.
20
     *
21
     * @return TreeBuilder The tree builder
22
     */
23
    public function getConfigTreeBuilder()
24
    {
25
        $treeBuilder = new TreeBuilder();
26
        $rootNode = $treeBuilder->root('sfcod_email_engine');
27
28
        $this->addMainSender($rootNode);
29
        $this->addSendersSection($rootNode);
30
        $this->addTemplatesSection($rootNode);
31
32
        return $treeBuilder;
33
    }
34
35
    /**
36
     * Add main sender node
37
     *
38
     * @param ArrayNodeDefinition $rootNode
39
     */
40
    private function addMainSender(ArrayNodeDefinition $rootNode)
41
    {
42
        $rootNode
43
            ->children()
44
                ->scalarNode('main_sender')
45
                    ->isRequired()
46
                    ->cannotBeEmpty()
47
                ->end()
48
            ->end();
49
    }
50
51
    /**
52
     * Add senders section
53
     *
54
     * @param ArrayNodeDefinition $rootNode
55
     */
56
    private function addSendersSection(ArrayNodeDefinition $rootNode)
57
    {
58
        $rootNode
59
            ->children()
60
                ->arrayNode('senders')
61
                    ->example([
62
                        'chained_sender' => [
63
                            'chain' => [
64
                                'senders' => [
65
                                    'first_sender',
66
                                    'second_sender',
67
                                ],
68
                            ],
69
                        ],
70
                        'first_sender' => [
71
                            'sender' => ['class' => 'SenderClass'],
72
                            'repository' => ['class' => 'RepositoryClass', 'arguments' => []],
73
                        ],
74
                        'second_sender' => [
75
                            'sender' => ['class' => 'SenderClass'],
76
                            'repository' => ['class' => 'RepositoryClass', 'arguments' => []],
77
                        ],
78
                    ])
79
                    ->isRequired()
80
                    ->requiresAtLeastOneElement()
81
                    ->useAttributeAsKey('name')
82
                    ->arrayPrototype()
83
                    ->children()
84
                        ->arrayNode('sender')
85
                            ->children()
86
                                ->scalarNode('class')->isRequired()->end()
87
                            ->end()
88
                        ->end()
89
                        ->arrayNode('repository')
90
                            ->children()
91
                                ->scalarNode('class')->isRequired()->end()
92
                                ->arrayNode('arguments')
93
                                    ->defaultValue([])
94
                                    ->scalarPrototype()->end()
95
                                ->end()
96
                            ->end()
97
                        ->end()
98
                    ->end()
99
                    ->children()
100
                        ->scalarNode('class')->end()
101
                            ->arrayNode('chain')
102
                                ->children()
103
                                    ->arrayNode('senders')
104
                                        ->scalarPrototype()->end()
105
                                    ->end()
106
                                ->end()
107
                            ->end()
108
                        ->end()
109
                    ->end()
110
                ->end()
111
            ->end();
112
    }
113
114
    /**
115
     * Add templates section
116
     *
117
     * @param ArrayNodeDefinition $rootNode
118
     */
119
    private function addTemplatesSection(ArrayNodeDefinition $rootNode)
120
    {
121
        $rootNode
122
            ->children()
123
                ->arrayNode('templates')
124
                    ->defaultValue([])
125
                    ->scalarPrototype()->end()
126
                ->end()
127
            ->end();
128
    }
129
}
130