1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lakion\SyliusCmsBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Lakion\SyliusCmsBundle\Document\Route; |
6
|
|
|
use Lakion\SyliusCmsBundle\Document\StaticContent; |
7
|
|
|
use Lakion\SyliusCmsBundle\Form\Type\RouteType; |
8
|
|
|
use Lakion\SyliusCmsBundle\Form\Type\StaticContentType; |
9
|
|
|
use Lakion\SyliusCmsBundle\Repository\StaticContentRepository; |
10
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
11
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
12
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
13
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
14
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
15
|
|
|
|
16
|
|
|
final class Configuration implements ConfigurationInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function getConfigTreeBuilder() |
22
|
|
|
{ |
23
|
|
|
$treeBuilder = new TreeBuilder(); |
24
|
|
|
$rootNode = $treeBuilder->root('lakion_sylius_cms'); |
25
|
|
|
|
26
|
|
|
$this->addResourcesSection($rootNode->children()); |
27
|
|
|
|
28
|
|
|
return $treeBuilder; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param NodeBuilder $rootNodeBuilder |
33
|
|
|
*/ |
34
|
|
|
private function addResourcesSection(NodeBuilder $rootNodeBuilder) |
35
|
|
|
{ |
36
|
|
|
$resourcesNodeBuilder = $rootNodeBuilder->arrayNode('resources')->addDefaultsIfNotSet()->children(); |
37
|
|
|
|
38
|
|
|
$this->addResourcesRouteSection($resourcesNodeBuilder); |
39
|
|
|
$this->addResourcesStaticContentSection($resourcesNodeBuilder); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
44
|
|
|
*/ |
45
|
|
|
private function addResourcesRouteSection(NodeBuilder $resourcesNodeBuilder) |
46
|
|
|
{ |
47
|
|
|
$resourcesNodeBuilder |
48
|
|
|
->arrayNode('route') |
49
|
|
|
->addDefaultsIfNotSet() |
50
|
|
|
->children() |
51
|
|
|
->arrayNode('classes') |
52
|
|
|
->addDefaultsIfNotSet() |
53
|
|
|
->children() |
54
|
|
|
->scalarNode('model')->defaultValue(Route::class)->cannotBeEmpty()->end() |
55
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
56
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
57
|
|
|
->scalarNode('form')->defaultValue(RouteType::class)->cannotBeEmpty()->end() |
58
|
|
|
; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param NodeBuilder $resourcesNodeBuilder |
63
|
|
|
*/ |
64
|
|
|
private function addResourcesStaticContentSection(NodeBuilder $resourcesNodeBuilder) |
65
|
|
|
{ |
66
|
|
|
$resourcesNodeBuilder |
67
|
|
|
->arrayNode('static_content') |
68
|
|
|
->addDefaultsIfNotSet() |
69
|
|
|
->children() |
70
|
|
|
->arrayNode('classes') |
71
|
|
|
->addDefaultsIfNotSet() |
72
|
|
|
->children() |
73
|
|
|
->scalarNode('model')->defaultValue(StaticContent::class)->cannotBeEmpty()->end() |
74
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
75
|
|
|
->scalarNode('repository')->defaultValue(StaticContentRepository::class)->cannotBeEmpty()->end() |
76
|
|
|
->scalarNode('form')->defaultValue(StaticContentType::class)->cannotBeEmpty()->end() |
77
|
|
|
; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|