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\ThemeBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
15
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceChoiceType; |
16
|
|
|
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Doctrine\ORM\ThemeRepository; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactory; |
19
|
|
|
use Sylius\Bundle\ThemeBundle\Model\Theme; |
20
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
21
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
22
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
23
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Kamil Kokot <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class Configuration implements ConfigurationInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function getConfigTreeBuilder() |
34
|
|
|
{ |
35
|
|
|
$treeBuilder = new TreeBuilder(); |
36
|
|
|
$rootNode = $treeBuilder->root('sylius_theme'); |
37
|
|
|
|
38
|
|
|
$this->addResourcesConfiguration($rootNode); |
39
|
|
|
$this->addSourcesConfiguration($rootNode); |
40
|
|
|
|
41
|
|
|
return $treeBuilder; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ArrayNodeDefinition $rootNode |
46
|
|
|
*/ |
47
|
|
|
private function addResourcesConfiguration(ArrayNodeDefinition $rootNode) |
48
|
|
|
{ |
49
|
|
|
$rootNode |
50
|
|
|
->addDefaultsIfNotSet() |
51
|
|
|
->children() |
52
|
|
|
->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end() |
53
|
|
|
->arrayNode('resources') |
54
|
|
|
->addDefaultsIfNotSet() |
55
|
|
|
->children() |
56
|
|
|
->arrayNode('theme') |
57
|
|
|
->addDefaultsIfNotSet() |
58
|
|
|
->children() |
59
|
|
|
->variableNode('options')->end() |
60
|
|
|
->arrayNode('classes') |
61
|
|
|
->addDefaultsIfNotSet() |
62
|
|
|
->children() |
63
|
|
|
->scalarNode('model')->defaultValue(Theme::class)->cannotBeEmpty()->end() |
64
|
|
|
->scalarNode('interface')->defaultValue(ThemeInterface::class)->cannotBeEmpty()->end() |
65
|
|
|
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
66
|
|
|
->scalarNode('repository')->cannotBeEmpty()->end() |
67
|
|
|
->scalarNode('factory')->defaultValue(ThemeFactory::class)->cannotBeEmpty()->end() |
68
|
|
|
->arrayNode('form') |
69
|
|
|
->addDefaultsIfNotSet() |
70
|
|
|
->children() |
71
|
|
|
->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end() |
72
|
|
|
->end() |
73
|
|
|
->end() |
74
|
|
|
->end() |
75
|
|
|
->end() |
76
|
|
|
->arrayNode('validation_groups') |
77
|
|
|
->addDefaultsIfNotSet() |
78
|
|
|
->children() |
79
|
|
|
->arrayNode('choice') |
80
|
|
|
->prototype('scalar')->end() |
81
|
|
|
->defaultValue(['sylius']) |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->end() |
87
|
|
|
; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param ArrayNodeDefinition $rootNode |
92
|
|
|
*/ |
93
|
|
|
private function addSourcesConfiguration(ArrayNodeDefinition $rootNode) |
94
|
|
|
{ |
95
|
|
|
$sourcesNodeBuilder = $rootNode |
96
|
|
|
->addDefaultsIfNotSet() |
97
|
|
|
->fixXmlConfig('source') |
98
|
|
|
->children() |
99
|
|
|
->arrayNode('sources') |
100
|
|
|
->addDefaultsIfNotSet() |
101
|
|
|
->children() |
102
|
|
|
; |
103
|
|
|
|
104
|
|
|
$sourcesNodeBuilder |
105
|
|
|
->arrayNode('filesystem') |
106
|
|
|
->addDefaultsIfNotSet() |
107
|
|
|
->fixXmlConfig('location') |
108
|
|
|
->children() |
109
|
|
|
->arrayNode('locations') |
110
|
|
|
->requiresAtLeastOneElement() |
111
|
|
|
->performNoDeepMerging() |
112
|
|
|
->defaultValue(['%kernel.root_dir%/themes', '%kernel.root_dir%/../vendor/sylius/themes']) |
113
|
|
|
->prototype('scalar') |
114
|
|
|
; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|