-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathConfiguration.php
133 lines (111 loc) · 4.24 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DependencyInjection;
use Psr\Log\LogLevel;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
const ONGR_CACHE_CONFIG = 'ongr.esb.cache';
const ONGR_SOURCE_DIR = 'ongr.esb.source_dir';
const ONGR_PROFILER_CONFIG = 'ongr.esb.profiler';
const ONGR_LOGGER_CONFIG = 'ongr.esb.logger';
const ONGR_ANALYSIS_CONFIG = 'ongr.esb.analysis';
const ONGR_INDEXES = 'ongr.esb.indexes';
const ONGR_DEFAULT_INDEX = 'ongr.esb.default_index';
const ONGR_INDEXES_OVERRIDE = 'ongr.esb.indexes_override';
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('ongr_elasticsearch');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('ongr_elasticsearch');
}
$rootNode
->children()
->booleanNode('cache')
->info(
'Enables the cache handler to store important data to the cache. '.
'Default value is kernel.debug parameter.'
)
->end()
->booleanNode('profiler')
->info(
'Enables Symfony profiler for the elasticsearch queries debug.'.
'Default value is kernel.debug parameter. '
)
->end()
->booleanNode('logger')
->defaultTrue()
->info(
'Enables executed queries logging. Log file names are the same as index.'
)
->end()
->arrayNode('source_directories')
->prototype('scalar')->end()
->defaultValue(['/src/Document'])
->info(
'If your documents are stored in a different folder than `/src/Document`, or several of them,' .
'you can specify them here to look automatically for ES documents.'
)
->end()
->arrayNode('indexes')
->defaultValue([])
->useAttributeAsKey('namespace')
->info(
'In case you want to override index settings defined in the annotation.' .
' e.g. use env variables instead.'
)
->prototype('variable')->end()
->end()
->append($this->getAnalysisNode())
->end();
return $treeBuilder;
}
private function getAnalysisNode(): NodeDefinition
{
$builder = new TreeBuilder('analysis');
if (method_exists($builder, 'getRootNode')) {
$node = $builder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$node = $builder->root('analysis');
}
$node
->info('Defines analyzers, normalizers, tokenizers and filters')
->addDefaultsIfNotSet()
->children()
->arrayNode('tokenizer')
->defaultValue([])
->prototype('variable')->end()
->end()
->arrayNode('filter')
->defaultValue([])
->prototype('variable')->end()
->end()
->arrayNode('analyzer')
->defaultValue([])
->prototype('variable')->end()
->end()
->arrayNode('normalizer')
->defaultValue([])
->prototype('variable')->end()
->end()
->arrayNode('char_filter')
->defaultValue([])
->prototype('variable')->end()
->end()
->end();
return $node;
}
}