1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Xervice\Elasticsearch; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Elastica\Client; |
8
|
|
|
use Xervice\Core\Business\Model\Dependency\Provider\AbstractDependencyProvider; |
9
|
|
|
use Xervice\Core\Business\Model\Dependency\DependencyContainerInterface; |
10
|
|
|
use Xervice\Elasticsearch\Business\Collection\IndexCollection; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @method \Xervice\Core\Locator\Locator getLocator() |
14
|
|
|
* @method \Xervice\Elasticsearch\ElasticsearchConfig getConfig() |
15
|
|
|
*/ |
16
|
|
|
class ElasticsearchDependencyProvider extends AbstractDependencyProvider |
17
|
|
|
{ |
18
|
|
|
public const CLIENT = 'elasticsearch.client'; |
19
|
|
|
|
20
|
|
|
public const INDEX_PROVIDER = 'elasticsearch.index.provider'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
24
|
|
|
* |
25
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
26
|
|
|
*/ |
27
|
1 |
|
public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface |
28
|
|
|
{ |
29
|
1 |
|
$container = $this->setClient($container); |
30
|
1 |
|
$container = $this->setIndexProvider($container); |
31
|
|
|
|
32
|
1 |
|
return $container; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
37
|
|
|
* |
38
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
39
|
|
|
*/ |
40
|
1 |
|
protected function setClient(DependencyContainerInterface $container): DependencyContainerInterface |
41
|
|
|
{ |
42
|
|
|
$container[self::CLIENT] = function (DependencyContainerInterface $container) { |
|
|
|
|
43
|
1 |
|
return $this->getClient(); |
44
|
|
|
}; |
45
|
|
|
|
46
|
1 |
|
return $container; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
51
|
|
|
* |
52
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
53
|
|
|
*/ |
54
|
1 |
|
protected function setIndexProvider(DependencyContainerInterface $container): DependencyContainerInterface |
55
|
|
|
{ |
56
|
|
|
$container[self::INDEX_PROVIDER] = function (DependencyContainerInterface $container) { |
|
|
|
|
57
|
1 |
|
return new IndexCollection( |
58
|
1 |
|
$this->getIndexProvider() |
59
|
|
|
); |
60
|
|
|
}; |
61
|
|
|
|
62
|
1 |
|
return $container; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return \Elastica\Client |
67
|
|
|
*/ |
68
|
1 |
|
protected function getClient() |
69
|
|
|
{ |
70
|
1 |
|
return new Client( |
71
|
|
|
[ |
72
|
1 |
|
'host' => $this->getConfig()->getHost(), |
73
|
1 |
|
'port' => $this->getConfig()->getPort() |
74
|
|
|
] |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return \Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface[] |
80
|
|
|
*/ |
81
|
1 |
|
protected function getIndexProvider(): array |
82
|
|
|
{ |
83
|
1 |
|
return []; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.