1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KGzocha\Bundle\SearcherBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Krzysztof Gzocha <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Configuration implements ConfigurationInterface |
13
|
|
|
{ |
14
|
|
|
const SEARCHER_CLASS = 'KGzocha\Searcher\Searcher'; |
15
|
|
|
const WRAPPER_CLASS = 'KGzocha\Searcher\WrappedResultsSearcher'; |
16
|
|
|
const CRITERIA_COLLECTION_CLASS = 'KGzocha\Searcher\Criteria\Collection\NamedCriteriaCollection'; |
17
|
|
|
const BUILDER_COLLECTION_CLASS = 'KGzocha\Searcher\CriteriaBuilder\Collection\CriteriaBuilderCollection'; |
18
|
|
|
const END_TRANSFORMER_CLASS = 'KGzocha\Searcher\Chain\EndTransformer'; |
19
|
|
|
const CHAIN_SEARCHER_CLASS = 'KGzocha\Searcher\Chain\ChainSearch'; |
20
|
|
|
const CELL_CLASS = 'KGzocha\Searcher\Chain\Cell'; |
21
|
|
|
const CELL_COLLECTION_CLASS = 'KGzocha\Searcher\Chain\Collection\CellCollection'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
25 |
|
public function getConfigTreeBuilder() |
27
|
|
|
{ |
28
|
25 |
|
$treeBuilder = new TreeBuilder(); |
29
|
25 |
|
$rootNode = $treeBuilder->root('k_gzocha_searcher'); |
30
|
|
|
|
31
|
|
|
$rootNode |
32
|
25 |
|
->canBeUnset(true) |
33
|
25 |
|
->children() |
34
|
25 |
|
->append($this->getContextsNode()) |
35
|
25 |
|
->append($this->getChainsNode()) |
36
|
25 |
|
->end(); |
37
|
|
|
|
38
|
25 |
|
return $treeBuilder; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return ArrayNodeDefinition |
43
|
|
|
*/ |
44
|
25 |
|
protected function getContextsNode() |
45
|
|
|
{ |
46
|
25 |
|
$node = new ArrayNodeDefinition('contexts'); |
47
|
|
|
|
48
|
|
|
$node |
49
|
25 |
|
->canBeUnset(true) |
50
|
25 |
|
->useAttributeAsKey('context_id') |
51
|
25 |
|
->prototype('array') |
52
|
25 |
|
->children() |
53
|
25 |
|
->append($this->getCriteriaCollectionNode()) |
54
|
25 |
|
->append($this->getBuilderCollectionNode()) |
55
|
25 |
|
->append($this->getCriteriaNode()) |
56
|
25 |
|
->append($this->getBuildersNode()) |
57
|
25 |
|
->append($this->getSearcher()) |
58
|
25 |
|
->append($this->getSearchingContextNode()) |
59
|
25 |
|
->end() |
60
|
25 |
|
->end(); |
61
|
|
|
|
62
|
25 |
|
return $node; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return ArrayNodeDefinition |
67
|
|
|
*/ |
68
|
25 |
|
protected function getChainsNode() |
69
|
|
|
{ |
70
|
25 |
|
$node = new ArrayNodeDefinition('chains'); |
71
|
|
|
|
72
|
|
|
$node |
73
|
25 |
|
->canBeUnset(true) |
74
|
25 |
|
->useAttributeAsKey('chain_id') |
75
|
25 |
|
->prototype('array') |
76
|
25 |
|
->children() |
77
|
25 |
|
->append($this->getCellCollectionNode()) |
78
|
25 |
|
->append($this->getChainSearcherNode()) |
79
|
25 |
|
->append($this->getTransformersNode()) |
80
|
25 |
|
->append($this->getCellsNode()) |
81
|
25 |
|
->end(); |
82
|
|
|
|
83
|
25 |
|
return $node; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return ArrayNodeDefinition |
88
|
|
|
*/ |
89
|
25 |
View Code Duplication |
protected function getCriteriaCollectionNode() |
90
|
|
|
{ |
91
|
25 |
|
$node = new ArrayNodeDefinition('criteria_collection'); |
92
|
|
|
|
93
|
|
|
$node |
94
|
25 |
|
->addDefaultsIfNotSet() |
95
|
25 |
|
->canBeUnset() |
96
|
25 |
|
->children() |
97
|
25 |
|
->scalarNode('class')->defaultValue(self::CRITERIA_COLLECTION_CLASS)->end() |
98
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
99
|
25 |
|
->end(); |
100
|
|
|
|
101
|
25 |
|
return $node; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return ArrayNodeDefinition |
106
|
|
|
*/ |
107
|
25 |
View Code Duplication |
protected function getBuilderCollectionNode() |
108
|
|
|
{ |
109
|
25 |
|
$node = new ArrayNodeDefinition('builder_collection'); |
110
|
|
|
|
111
|
|
|
$node |
112
|
25 |
|
->addDefaultsIfNotSet() |
113
|
25 |
|
->canBeUnset() |
114
|
25 |
|
->children() |
115
|
25 |
|
->scalarNode('class')->defaultValue(self::BUILDER_COLLECTION_CLASS)->end() |
116
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
117
|
25 |
|
->end(); |
118
|
|
|
|
119
|
25 |
|
return $node; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return ArrayNodeDefinition |
124
|
|
|
*/ |
125
|
25 |
View Code Duplication |
protected function getSearcher() |
126
|
|
|
{ |
127
|
25 |
|
$node = new ArrayNodeDefinition('searcher'); |
128
|
|
|
|
129
|
|
|
$node |
130
|
25 |
|
->addDefaultsIfNotSet() |
131
|
25 |
|
->canBeUnset() |
132
|
25 |
|
->children() |
133
|
25 |
|
->scalarNode('class')->defaultValue(self::SEARCHER_CLASS)->end() |
134
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
135
|
25 |
|
->scalarNode('wrapper_class')->defaultValue(self::WRAPPER_CLASS)->end() |
136
|
25 |
|
->end(); |
137
|
|
|
|
138
|
25 |
|
return $node; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return ArrayNodeDefinition |
143
|
|
|
*/ |
144
|
25 |
View Code Duplication |
protected function getSearchingContextNode() |
145
|
|
|
{ |
146
|
25 |
|
$node = new ArrayNodeDefinition('context'); |
147
|
|
|
|
148
|
|
|
$node |
149
|
25 |
|
->addDefaultsIfNotSet() |
150
|
25 |
|
->canBeUnset() |
151
|
25 |
|
->children() |
152
|
25 |
|
->scalarNode('class')->defaultValue(null)->end() |
153
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
154
|
25 |
|
->end(); |
155
|
|
|
|
156
|
25 |
|
return $node; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return ArrayNodeDefinition |
161
|
|
|
*/ |
162
|
25 |
View Code Duplication |
protected function getCriteriaNode() |
163
|
|
|
{ |
164
|
25 |
|
$node = new ArrayNodeDefinition('criteria'); |
165
|
|
|
|
166
|
|
|
$node |
167
|
25 |
|
->prototype('array') |
168
|
25 |
|
->children() |
169
|
25 |
|
->scalarNode('class')->defaultValue(null)->end() |
170
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
171
|
25 |
|
->scalarNode('name')->cannotBeEmpty()->isRequired()->end() |
172
|
25 |
|
->end(); |
173
|
|
|
|
174
|
25 |
|
return $node; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return ArrayNodeDefinition |
179
|
|
|
*/ |
180
|
25 |
View Code Duplication |
protected function getBuildersNode() |
181
|
|
|
{ |
182
|
25 |
|
$node = new ArrayNodeDefinition('builders'); |
183
|
|
|
|
184
|
|
|
$node |
185
|
25 |
|
->prototype('array') |
186
|
25 |
|
->children() |
187
|
25 |
|
->scalarNode('class')->defaultValue(null)->end() |
188
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
189
|
25 |
|
->scalarNode('name')->cannotBeEmpty()->isRequired()->end() |
190
|
25 |
|
->end(); |
191
|
|
|
|
192
|
25 |
|
return $node; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return ArrayNodeDefinition |
197
|
|
|
*/ |
198
|
25 |
View Code Duplication |
protected function getChainSearcherNode() |
199
|
|
|
{ |
200
|
25 |
|
$node = new ArrayNodeDefinition('chain_searcher'); |
201
|
|
|
|
202
|
|
|
$node |
203
|
25 |
|
->addDefaultsIfNotSet() |
204
|
25 |
|
->canBeUnset() |
205
|
25 |
|
->children() |
206
|
25 |
|
->scalarNode('class')->defaultValue(self::CHAIN_SEARCHER_CLASS)->end() |
207
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
208
|
25 |
|
->end(); |
209
|
|
|
|
210
|
25 |
|
return $node; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return ArrayNodeDefinition |
215
|
|
|
*/ |
216
|
25 |
View Code Duplication |
protected function getTransformersNode() |
217
|
|
|
{ |
218
|
25 |
|
$node = new ArrayNodeDefinition('transformers'); |
219
|
|
|
|
220
|
|
|
$node |
221
|
25 |
|
->prototype('array') |
222
|
25 |
|
->children() |
223
|
25 |
|
->scalarNode('name')->cannotBeEmpty()->isRequired()->end() |
224
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
225
|
25 |
|
->scalarNode('class')->defaultValue(null)->end() |
226
|
25 |
|
->end(); |
227
|
|
|
|
228
|
25 |
|
return $node; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return ArrayNodeDefinition |
233
|
|
|
*/ |
234
|
25 |
|
protected function getCellsNode() |
235
|
|
|
{ |
236
|
25 |
|
$node = new ArrayNodeDefinition('cells'); |
237
|
|
|
|
238
|
|
|
$node |
239
|
25 |
|
->prototype('array') |
240
|
25 |
|
->children() |
241
|
25 |
|
->scalarNode('name')->cannotBeEmpty()->isRequired()->end() |
242
|
25 |
|
->scalarNode('searcher')->cannotBeEmpty()->isRequired()->end() |
243
|
25 |
|
->scalarNode('transformer')->defaultNull()->end() |
244
|
25 |
|
->scalarNode('class')->defaultValue(self::CELL_CLASS)->end() |
245
|
25 |
|
->scalarNode('service')->defaultValue(null)->end() |
246
|
25 |
|
->end(); |
247
|
|
|
|
248
|
25 |
|
return $node; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return ArrayNodeDefinition |
253
|
|
|
*/ |
254
|
25 |
View Code Duplication |
private function getCellCollectionNode() |
255
|
|
|
{ |
256
|
25 |
|
$node = new ArrayNodeDefinition('cell_collection'); |
257
|
|
|
|
258
|
|
|
$node |
259
|
25 |
|
->addDefaultsIfNotSet() |
260
|
25 |
|
->canBeUnset() |
261
|
25 |
|
->children() |
262
|
25 |
|
->scalarNode('class')->defaultValue(self::CELL_COLLECTION_CLASS)->end() |
263
|
25 |
|
->scalarNode('service')->defaultNull()->end() |
264
|
25 |
|
->end(); |
265
|
|
|
|
266
|
25 |
|
return $node; |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|