1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pgs\ElasticOM\Bridge\Symfony; |
4
|
|
|
|
5
|
|
|
use Pgs\ElasticOM\Adapter; |
6
|
|
|
use Pgs\ElasticOM\AdapterFactory; |
7
|
|
|
use Pgs\ElasticOM\EntityRepositoryManager; |
8
|
|
|
use Pgs\ElasticOM\ElasticApi\ApiService; |
9
|
|
|
use Pgs\ElasticOM\ElasticApi\ApiServiceFactory; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
13
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
14
|
|
|
|
15
|
|
|
class ElasticOMExtension extends Extension |
16
|
|
|
{ |
17
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
18
|
|
|
{ |
19
|
1 |
|
$configuration = new Configuration(); |
20
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
21
|
|
|
|
22
|
1 |
|
$arguments = array_intersect_key($config, array_flip(['host', 'port', 'index'])); |
23
|
1 |
|
$serviceDefinition = new Definition(ApiService::class, $arguments); |
24
|
1 |
|
$serviceDefinition->setFactory([ApiServiceFactory::class, 'create']); |
25
|
|
|
|
26
|
1 |
|
$container->setDefinition('elastic_om.service', $serviceDefinition); |
27
|
|
|
|
28
|
1 |
|
$adapterDefinition = new Definition(Adapter::class, $arguments); |
29
|
1 |
|
$adapterDefinition->setFactory([AdapterFactory::class, 'create']); |
30
|
|
|
|
31
|
1 |
|
$container->setDefinition('elastic_om.adapter', $adapterDefinition)->setPublic(false); |
32
|
|
|
|
33
|
1 |
|
$repositoryDefinition = new Definition( |
34
|
1 |
|
EntityRepositoryManager::class, |
35
|
1 |
|
[new Reference('elastic_om.adapter')] |
36
|
|
|
); |
37
|
|
|
|
38
|
1 |
|
$container->setDefinition('elastic_om.entity_repository_manager', $repositoryDefinition); |
39
|
1 |
|
} |
40
|
|
|
} |
41
|
|
|
|