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\Configuration; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Kamil Kokot <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class ThemeConfiguration implements ConfigurationInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getConfigTreeBuilder() |
27
|
|
|
{ |
28
|
|
|
$treeBuilder = new TreeBuilder(); |
29
|
|
|
$rootNodeDefinition = $treeBuilder->root('sylius_theme'); |
30
|
|
|
|
31
|
|
|
$rootNodeDefinition->ignoreExtraKeys(); |
32
|
|
|
|
33
|
|
|
$this->addRequiredNameField($rootNodeDefinition); |
34
|
|
|
$this->addOptionalTitleField($rootNodeDefinition); |
35
|
|
|
$this->addOptionalDescriptionField($rootNodeDefinition); |
36
|
|
|
$this->addOptionalPathField($rootNodeDefinition); |
37
|
|
|
$this->addOptionalParentsList($rootNodeDefinition); |
38
|
|
|
$this->addOptionalAuthorsList($rootNodeDefinition); |
39
|
|
|
|
40
|
|
|
return $treeBuilder; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ArrayNodeDefinition $rootNodeDefinition |
45
|
|
|
*/ |
46
|
|
|
private function addRequiredNameField(ArrayNodeDefinition $rootNodeDefinition) |
47
|
|
|
{ |
48
|
|
|
$rootNodeDefinition->children()->scalarNode('name')->isRequired()->cannotBeEmpty(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param ArrayNodeDefinition $rootNodeDefinition |
53
|
|
|
*/ |
54
|
|
|
private function addOptionalTitleField(ArrayNodeDefinition $rootNodeDefinition) |
55
|
|
|
{ |
56
|
|
|
$rootNodeDefinition->children()->scalarNode('title')->cannotBeEmpty(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param ArrayNodeDefinition $rootNodeDefinition |
61
|
|
|
*/ |
62
|
|
|
private function addOptionalDescriptionField(ArrayNodeDefinition $rootNodeDefinition) |
63
|
|
|
{ |
64
|
|
|
$rootNodeDefinition->children()->scalarNode('description')->cannotBeEmpty(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param ArrayNodeDefinition $rootNodeDefinition |
69
|
|
|
*/ |
70
|
|
|
private function addOptionalPathField(ArrayNodeDefinition $rootNodeDefinition) |
71
|
|
|
{ |
72
|
|
|
$rootNodeDefinition->children()->scalarNode('path')->cannotBeEmpty(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ArrayNodeDefinition $rootNodeDefinition |
77
|
|
|
*/ |
78
|
|
|
private function addOptionalParentsList(ArrayNodeDefinition $rootNodeDefinition) |
79
|
|
|
{ |
80
|
|
|
$parentsNodeDefinition = $rootNodeDefinition->children()->arrayNode('parents'); |
81
|
|
|
$parentsNodeDefinition |
82
|
|
|
->requiresAtLeastOneElement() |
83
|
|
|
->performNoDeepMerging() |
84
|
|
|
->prototype('scalar') |
85
|
|
|
->cannotBeEmpty() |
86
|
|
|
; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param ArrayNodeDefinition $rootNodeDefinition |
91
|
|
|
*/ |
92
|
|
|
private function addOptionalAuthorsList(ArrayNodeDefinition $rootNodeDefinition) |
93
|
|
|
{ |
94
|
|
|
$authorsNodeDefinition = $rootNodeDefinition->children()->arrayNode('authors'); |
95
|
|
|
$authorsNodeDefinition |
96
|
|
|
->requiresAtLeastOneElement() |
97
|
|
|
->performNoDeepMerging() |
98
|
|
|
; |
99
|
|
|
|
100
|
|
|
/** @var ArrayNodeDefinition $authorNodeDefinition */ |
101
|
|
|
$authorNodeDefinition = $authorsNodeDefinition->prototype('array'); |
102
|
|
|
$authorNodeDefinition |
103
|
|
|
->validate() |
104
|
|
|
->ifTrue(function ($author) { |
105
|
|
|
return [] === $author; |
106
|
|
|
}) |
107
|
|
|
->thenInvalid('Author cannot be empty!') |
108
|
|
|
; |
109
|
|
|
|
110
|
|
|
$authorNodeBuilder = $authorNodeDefinition->children(); |
111
|
|
|
$authorNodeBuilder->scalarNode('name')->cannotBeEmpty(); |
112
|
|
|
$authorNodeBuilder->scalarNode('email')->cannotBeEmpty(); |
113
|
|
|
$authorNodeBuilder->scalarNode('homepage')->cannotBeEmpty(); |
114
|
|
|
$authorNodeBuilder->scalarNode('role')->cannotBeEmpty(); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|