|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bardex\Elastic; |
|
4
|
|
|
|
|
5
|
|
|
use Elasticsearch\Client as ElasticClient; |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @package Bardex\Elastic |
|
10
|
|
|
* @author Alexey Sumin <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class PrototypeQuery |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ElasticClient $client |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $elastic; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var IListener[] |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $listeners = []; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param ElasticClient $elastic |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(ElasticClient $elastic) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->elastic = $elastic; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return ElasticClient |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getElasticClient() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->elastic; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $elastic |
|
43
|
|
|
*/ |
|
44
|
|
|
public function setElasticClient($elastic) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->elastic = $elastic; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return IListener[] |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getListeners() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->listeners; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Create new instance of SearchQuery |
|
59
|
|
|
* @return SearchQuery |
|
60
|
|
|
*/ |
|
61
|
|
|
public function createSearchQuery() |
|
62
|
|
|
{ |
|
63
|
|
|
$query = new SearchQuery($this->elastic); |
|
64
|
|
|
$query->listeners = $this->listeners; |
|
|
|
|
|
|
65
|
|
|
return $query; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Create new instance of MultiQuery |
|
70
|
|
|
* @return MultiQuery |
|
71
|
|
|
*/ |
|
72
|
|
|
public function createMultiQuery() |
|
73
|
|
|
{ |
|
74
|
|
|
$query = new MultiQuery($this->elastic); |
|
75
|
|
|
$query->listeners = $this->listeners; |
|
|
|
|
|
|
76
|
|
|
return $query; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param IListener $listener |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
|
|
public function addListener(IListener $listener) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->listeners[] = $listener; |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param IListener $listener |
|
91
|
|
|
* @return $this |
|
92
|
|
|
*/ |
|
93
|
|
|
public function removeListener(IListener $listener) |
|
94
|
|
|
{ |
|
95
|
|
|
foreach ($this->listeners as $i => $listItem) { |
|
96
|
|
|
if ($listener === $listItem) { |
|
97
|
|
|
unset($this->listeners[$i]); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
} |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.