Completed
Push — master ( 22394a...0baaef )
by Vladimir
02:13
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace Koff\Bundle\I18nFormBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * Class Configuration.
10
 *
11
 * @author David ALLIX
12
 * @author Gonzalo Vilaseca <[email protected]> . Reiss Clothing Ltd.
13
 * @author Sadicov Vladimir <[email protected]>
14
 */
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function getConfigTreeBuilder()
21
    {
22
        $treeBuilder = new TreeBuilder();
23
        $root = $treeBuilder->root('koff_i18n_form')->children();
24
25
        $convertStringToArray = function ($v) {
26
            return preg_split('/\s*[,|]\s*/', $v);
27
        };
28
29
        $locales = $root->arrayNode('locales');
30
        $locales->defaultValue(['en']);
31
        $locales->beforeNormalization()->ifString()->then($convertStringToArray);
32
        $locales->requiresAtLeastOneElement();
33
        $locales->prototype('scalar');
34
35
        $required = $root->arrayNode('required_locales');
36
        $required->beforeNormalization()->ifString()->then($convertStringToArray);
37
        $required->prototype('scalar');
38
39
        $excluded = $root->arrayNode('excluded_fields');
40
        $excluded->defaultValue(['id', 'locale', 'translatable']);
41
        $excluded->beforeNormalization()->ifString()->then($convertStringToArray);
42
        $excluded->prototype('scalar');
43
44
        return $treeBuilder;
45
    }
46
}
47