1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Xervice\Elasticsearch\Business; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Elastica\Client; |
8
|
|
|
use Xervice\Core\Business\Model\Factory\AbstractBusinessFactory; |
9
|
|
|
use Xervice\Elasticsearch\Business\Collection\IndexCollection; |
10
|
|
|
use Xervice\Elasticsearch\Business\Model\Document\DocumentBuilder; |
11
|
|
|
use Xervice\Elasticsearch\Business\Model\Document\DocumentBuilderInterface; |
12
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\IndexBuilder; |
13
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\IndexBuilderInterface; |
14
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\MappingConverter; |
15
|
|
|
use Xervice\Elasticsearch\Business\Model\Index\MappingConverterInterface; |
16
|
|
|
use Xervice\Elasticsearch\Business\Model\Indexer; |
17
|
|
|
use Xervice\Elasticsearch\Business\Model\IndexerInterface; |
18
|
|
|
use Xervice\Elasticsearch\ElasticsearchDependencyProvider; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @method \Xervice\Elasticsearch\ElasticsearchConfig getConfig() |
22
|
|
|
*/ |
23
|
|
|
class ElasticsearchBusinessFactory extends AbstractBusinessFactory |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Document\DocumentBuilderInterface |
27
|
|
|
*/ |
28
|
1 |
|
public function createDocumentBuilder(): DocumentBuilderInterface |
29
|
|
|
{ |
30
|
1 |
|
return new DocumentBuilder( |
31
|
1 |
|
$this->getClient() |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\IndexerInterface |
37
|
|
|
*/ |
38
|
1 |
|
public function createIndexer(): IndexerInterface |
39
|
|
|
{ |
40
|
1 |
|
return new Indexer( |
41
|
1 |
|
$this->getIndexProviderCollection(), |
42
|
1 |
|
$this->createIndexBuilder(), |
43
|
1 |
|
$this->createMappingConverter() |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Index\MappingConverterInterface |
49
|
|
|
*/ |
50
|
4 |
|
public function createMappingConverter(): MappingConverterInterface |
51
|
|
|
{ |
52
|
4 |
|
return new MappingConverter(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return \Xervice\Elasticsearch\Business\Model\Index\IndexBuilderInterface |
57
|
|
|
*/ |
58
|
4 |
|
public function createIndexBuilder(): IndexBuilderInterface |
59
|
|
|
{ |
60
|
4 |
|
return new IndexBuilder( |
61
|
4 |
|
$this->getClient() |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return \Elastica\Client |
67
|
|
|
*/ |
68
|
4 |
|
public function getClient(): Client |
69
|
|
|
{ |
70
|
4 |
|
return $this->getDependency(ElasticsearchDependencyProvider::CLIENT); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return \Xervice\Elasticsearch\Business\Collection\IndexCollection |
75
|
|
|
*/ |
76
|
1 |
|
public function getIndexProviderCollection(): IndexCollection |
77
|
|
|
{ |
78
|
1 |
|
return $this->getDependency(ElasticsearchDependencyProvider::INDEX_PROVIDER); |
79
|
|
|
} |
80
|
|
|
} |