-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathConfiguration.php
More file actions
92 lines (87 loc) · 3.87 KB
/
Configuration.php
File metadata and controls
92 lines (87 loc) · 3.87 KB
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
<?php
namespace Algolia\SearchBundle\DependencyInjection;
use Algolia\SearchBundle\Searchable;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use function method_exists;
/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder('algolia_search');
$rootNode = $treeBuilder->getRootNode();
} else {
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('algolia_search');
}
$rootNode
->children()
->scalarNode('prefix')
->defaultValue(null)
->end()
->scalarNode('nbResults')
->defaultValue(20)
->end()
->scalarNode('settingsDirectory')
->defaultValue(null)
->end()
->scalarNode('batchSize')
->defaultValue(500)
->end()
->arrayNode('doctrineSubscribedEvents')
->prototype('scalar')->end()
->defaultValue(['postPersist', 'postUpdate', 'preRemove'])
->end()
->scalarNode('serializer')
->defaultValue('serializer')
->end()
->arrayNode('indices')
->useAttributeAsKey('name')
->arrayPrototype()
->beforeNormalization()
->ifTrue(function($v) {
return !empty($v['serializer_groups']) &&
(!isset($v['enable_serializer_groups']) || !$v['enable_serializer_groups']);
})
->thenInvalid('In order to specify "serializer_groups" you need to enable "enable_serializer_groups"')
->end()
->children()
->scalarNode('class')
->isRequired()
->cannotBeEmpty()
->end()
->booleanNode('enable_serializer_groups')
->info(
'When set to true, it will call normalize method with an extra groups ' .
'defined in "serializer_groups" (Searchable::NORMALIZATION_GROUP by default)'
)
->defaultFalse()
->end()
->arrayNode('serializer_groups')
->info('List of serializer groups to use while serializing. This option requires "enable_serializer_groups" set to true.')
->beforeNormalization()
->castToArray()
->end()
->scalarPrototype()->end()
->defaultValue([Searchable::NORMALIZATION_GROUP])
->end()
->scalarNode('index_if')
->info('Property accessor path (like method or property name) used to decide if an entry should be indexed.')
->defaultNull()
->end()
->end()
->end()
->end() // indices
->end();
return $treeBuilder;
}
}