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