|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
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 ONGR\ElasticsearchBundle\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Compiles elastic search data. |
|
21
|
|
|
*/ |
|
22
|
|
|
class MappingPass implements CompilerPassInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function process(ContainerBuilder $container) |
|
28
|
|
|
{ |
|
29
|
|
|
$analysis = $container->getParameter('es.analysis'); |
|
30
|
|
|
$managers = $container->getParameter('es.managers'); |
|
31
|
|
|
|
|
32
|
|
|
$collector = $container->get('es.metadata_collector'); |
|
33
|
|
|
|
|
34
|
|
|
foreach ($managers as $managerName => $manager) { |
|
35
|
|
|
$connection = $manager['index']; |
|
36
|
|
|
$managerName = strtolower($managerName); |
|
37
|
|
|
|
|
38
|
|
|
$managerDefinition = new Definition( |
|
39
|
|
|
'ONGR\ElasticsearchBundle\Service\Manager', |
|
40
|
|
|
[ |
|
41
|
|
|
$managerName, |
|
42
|
|
|
$connection, |
|
43
|
|
|
$analysis, |
|
44
|
|
|
$manager, |
|
45
|
|
|
] |
|
46
|
|
|
); |
|
47
|
|
|
$managerDefinition->setFactory( |
|
48
|
|
|
[ |
|
49
|
|
|
new Reference('es.manager_factory'), |
|
50
|
|
|
'createManager', |
|
51
|
|
|
] |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition); |
|
55
|
|
|
|
|
56
|
|
|
// Make es.manager.default as es.manager service. |
|
57
|
|
|
if ($managerName === 'default') { |
|
58
|
|
|
$container->setAlias('es.manager', 'es.manager.default'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$mappings = $collector->getMappings($manager['mappings']); |
|
62
|
|
|
|
|
63
|
|
|
// Building repository services. |
|
64
|
|
|
foreach ($mappings as $repositoryType => $repositoryDetails) { |
|
65
|
|
|
$repositoryDefinition = new Definition( |
|
66
|
|
|
'ONGR\ElasticsearchBundle\Service\Repository', |
|
67
|
|
|
[$repositoryDetails['namespace']] |
|
68
|
|
|
); |
|
69
|
|
|
$repositoryDefinition->setFactory( |
|
70
|
|
|
[ |
|
71
|
|
|
new Reference(sprintf('es.manager.%s', $managerName)), |
|
72
|
|
|
'getRepository', |
|
73
|
|
|
] |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType); |
|
77
|
|
|
$container->setDefinition($repositoryId, $repositoryDefinition); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|