1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lakion\CmsPlugin\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Lakion\CmsPlugin\Document\CustomBlock; |
6
|
|
|
use Lakion\CmsPlugin\Document\ProductBlock; |
7
|
|
|
use Lakion\CmsPlugin\Document\Route; |
8
|
|
|
use Lakion\CmsPlugin\Document\StaticContent; |
9
|
|
|
use Lakion\CmsPlugin\Document\StringBlock; |
10
|
|
|
use Lakion\CmsPlugin\Form\Type\CustomBlockType; |
11
|
|
|
use Lakion\CmsPlugin\Form\Type\ProductBlockType; |
12
|
|
|
use Lakion\CmsPlugin\Form\Type\RouteType; |
13
|
|
|
use Lakion\CmsPlugin\Form\Type\StaticContentType; |
14
|
|
|
use Lakion\CmsPlugin\Form\Type\StringBlockType; |
15
|
|
|
use Lakion\CmsPlugin\Repository\StaticContentRepository; |
16
|
|
|
use Lakion\CmsPlugin\Document\TaxonBlock; |
17
|
|
|
use Lakion\CmsPlugin\Form\Type\TaxonBlockType; |
18
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
20
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
21
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
22
|
|
|
|
23
|
|
|
final class Configuration implements ConfigurationInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function getConfigTreeBuilder() |
29
|
|
|
{ |
30
|
|
|
$treeBuilder = new TreeBuilder(); |
31
|
|
|
$rootNode = $treeBuilder->root('lakion_cms'); |
32
|
|
|
|
33
|
|
|
$this->addResourcesSection($rootNode->children()); |
34
|
|
|
|
35
|
|
|
return $treeBuilder; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param NodeBuilder $rootNodeBuilder |
40
|
|
|
*/ |
41
|
|
|
private function addResourcesSection(NodeBuilder $rootNodeBuilder) |
42
|
|
|
{ |
43
|
|
|
$resourcesNodeBuilder = $rootNodeBuilder->arrayNode('resources')->addDefaultsIfNotSet()->children(); |
44
|
|
|
|
45
|
|
|
$this->addResourcesCustomBlockSection($resourcesNodeBuilder); |
46
|
|
|
$this->addResourcesProductBlockSection($resourcesNodeBuilder); |
47
|
|
|
$this->addResourcesRouteSection($resourcesNodeBuilder); |
48
|
|
|
$this->addResourcesStaticContentSection($resourcesNodeBuilder); |
49
|
|
|
$this->addResourcesStringBlockSection($resourcesNodeBuilder); |
50
|
|
|
$this->addResourcesTaxonBlockSection($resourcesNodeBuilder); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
private function addResourcesCustomBlockSection(NodeBuilder $resourcesNodeBuilder) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$resourcesNodeBuilder |
59
|
|
|
->arrayNode('custom_block') |
60
|
|
|
->addDefaultsIfNotSet() |
61
|
|
|
->children() |
62
|
|
|
->arrayNode('classes') |
63
|
|
|
->addDefaultsIfNotSet() |
64
|
|
|
->children() |
65
|
|
|
->scalarNode('model')->defaultValue(CustomBlock::class)->cannotBeEmpty()->end() |
66
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
67
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
68
|
|
|
->scalarNode('form')->defaultValue(CustomBlockType::class)->cannotBeEmpty()->end() |
69
|
|
|
; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
private function addResourcesProductBlockSection(NodeBuilder $resourcesNodeBuilder) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$resourcesNodeBuilder |
78
|
|
|
->arrayNode('product_block') |
79
|
|
|
->addDefaultsIfNotSet() |
80
|
|
|
->children() |
81
|
|
|
->arrayNode('classes') |
82
|
|
|
->addDefaultsIfNotSet() |
83
|
|
|
->children() |
84
|
|
|
->scalarNode('model')->defaultValue(ProductBlock::class)->cannotBeEmpty()->end() |
85
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
86
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
87
|
|
|
->scalarNode('form')->defaultValue(ProductBlockType::class)->cannotBeEmpty()->end() |
88
|
|
|
; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
private function addResourcesRouteSection(NodeBuilder $resourcesNodeBuilder) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$resourcesNodeBuilder |
97
|
|
|
->arrayNode('route') |
98
|
|
|
->addDefaultsIfNotSet() |
99
|
|
|
->children() |
100
|
|
|
->arrayNode('classes') |
101
|
|
|
->addDefaultsIfNotSet() |
102
|
|
|
->children() |
103
|
|
|
->scalarNode('model')->defaultValue(Route::class)->cannotBeEmpty()->end() |
104
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
105
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
106
|
|
|
->scalarNode('form')->defaultValue(RouteType::class)->cannotBeEmpty()->end() |
107
|
|
|
; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
112
|
|
|
*/ |
113
|
|
|
private function addResourcesStaticContentSection(NodeBuilder $resourcesNodeBuilder) |
114
|
|
|
{ |
115
|
|
|
$resourcesNodeBuilder |
116
|
|
|
->arrayNode('static_content') |
117
|
|
|
->addDefaultsIfNotSet() |
118
|
|
|
->children() |
119
|
|
|
->arrayNode('classes') |
120
|
|
|
->addDefaultsIfNotSet() |
121
|
|
|
->children() |
122
|
|
|
->scalarNode('model')->defaultValue(StaticContent::class)->cannotBeEmpty()->end() |
123
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
124
|
|
|
->scalarNode('repository')->defaultValue(StaticContentRepository::class)->cannotBeEmpty()->end() |
125
|
|
|
->scalarNode('form')->defaultValue(StaticContentType::class)->cannotBeEmpty()->end() |
126
|
|
|
; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
131
|
|
|
*/ |
132
|
|
View Code Duplication |
private function addResourcesStringBlockSection(NodeBuilder $resourcesNodeBuilder) |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
$resourcesNodeBuilder |
135
|
|
|
->arrayNode('string_block') |
136
|
|
|
->addDefaultsIfNotSet() |
137
|
|
|
->children() |
138
|
|
|
->arrayNode('classes') |
139
|
|
|
->addDefaultsIfNotSet() |
140
|
|
|
->children() |
141
|
|
|
->scalarNode('model')->defaultValue(StringBlock::class)->cannotBeEmpty()->end() |
142
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
143
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
144
|
|
|
->scalarNode('form')->defaultValue(StringBlockType::class)->cannotBeEmpty()->end() |
145
|
|
|
; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
150
|
|
|
*/ |
151
|
|
View Code Duplication |
private function addResourcesTaxonBlockSection(NodeBuilder $resourcesNodeBuilder) |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$resourcesNodeBuilder |
154
|
|
|
->arrayNode('taxon_block') |
155
|
|
|
->addDefaultsIfNotSet() |
156
|
|
|
->children() |
157
|
|
|
->arrayNode('classes') |
158
|
|
|
->addDefaultsIfNotSet() |
159
|
|
|
->children() |
160
|
|
|
->scalarNode('model')->defaultValue(TaxonBlock::class)->cannotBeEmpty()->end() |
161
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
162
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
163
|
|
|
->scalarNode('form')->defaultValue(TaxonBlockType::class)->cannotBeEmpty()->end() |
164
|
|
|
; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.