Completed
Push — master ( 90ccc1...22512f )
by Kamil
35:43
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 69
rs 10
c 4
b 0
f 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 15 1
B addResourcesSection() 0 44 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\MetadataBundle\DependencyInjection;
13
14
use Sylius\Bundle\MetadataBundle\Controller\MetadataController;
15
use Sylius\Bundle\MetadataBundle\Form\Type\MetadataContainerType;
16
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
17
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
18
use Sylius\Bundle\MetadataBundle\Model\MetadataContainer;
19
use Sylius\Component\Metadata\Factory\MetadataContainerFactory;
20
use Sylius\Component\Metadata\Model\MetadataContainerInterface;
21
use Sylius\Component\Resource\Factory\Factory;
22
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
23
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
24
use Symfony\Component\Config\Definition\ConfigurationInterface;
25
26
/**
27
 * This class contains the configuration information for the bundle.
28
 *
29
 * This information is solely responsible for how the different configuration
30
 * sections are normalized, and merged.
31
 *
32
 * @author Kamil Kokot <[email protected]>
33
 */
34
class Configuration implements ConfigurationInterface
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getConfigTreeBuilder()
40
    {
41
        $treeBuilder = new TreeBuilder();
42
        $rootNode = $treeBuilder->root('sylius_metadata');
43
44
        $rootNode
45
            ->children()
46
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
47
            ->end()
48
        ;
49
50
        $this->addResourcesSection($rootNode);
51
52
        return $treeBuilder;
53
    }
54
55
    /**
56
     * @param ArrayNodeDefinition $node
57
     */
58
    private function addResourcesSection(ArrayNodeDefinition $node)
59
    {
60
        $resourcesBuilder = $node
61
            ->fixXmlConfig('resource')
62
            ->children()
63
                ->arrayNode('resources')
64
                    ->addDefaultsIfNotSet()
65
                    ->children()
66
        ;
67
68
        $resourcesBuilder
69
            ->arrayNode('metadata_container')
70
                ->addDefaultsIfNotSet()
71
                ->children()
72
                    ->variableNode('options')->end()
73
                    ->arrayNode('classes')
74
                        ->addDefaultsIfNotSet()
75
                        ->children()
76
                            ->scalarNode('model')->defaultValue(MetadataContainer::class)->cannotBeEmpty()->end()
77
                            ->scalarNode('interface')->defaultValue(MetadataContainerInterface::class)->cannotBeEmpty()->end()
78
                            ->scalarNode('controller')->defaultValue(MetadataController::class)->cannotBeEmpty()->end()
79
                            ->scalarNode('repository')->cannotBeEmpty()->end()
80
                            ->scalarNode('factory')->defaultValue(MetadataContainerFactory::class)->end()
81
                            ->arrayNode('form')
82
                                ->addDefaultsIfNotSet()
83
                                ->children()
84
                                    ->scalarNode('default')->defaultValue(MetadataContainerType::class)->cannotBeEmpty()->end()
85
                                ->end()
86
                            ->end()
87
                        ->end()
88
                    ->end()
89
                    ->arrayNode('validation_groups')
90
                        ->addDefaultsIfNotSet()
91
                        ->children()
92
                            ->arrayNode('default')
93
                                ->prototype('scalar')->end()
94
                                ->defaultValue(array('sylius'))
95
                            ->end()
96
                        ->end()
97
                    ->end()
98
                ->end()
99
            ->end()
100
        ;
101
    }
102
}
103