1
|
|
|
<?php |
2
|
|
|
namespace Elastica\Transport; |
3
|
|
|
|
4
|
|
|
use Elastica\JSON; |
5
|
|
|
use Elastica\Request; |
6
|
|
|
use Elastica\Response; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Elastica Null Transport object. |
10
|
|
|
* |
11
|
|
|
* This is used in case you just need a test transport that doesn't do any connection to an elasticsearch |
12
|
|
|
* host but still returns a valid response object |
13
|
|
|
* |
14
|
|
|
* @author James Boehmer <[email protected]> |
15
|
|
|
* @author Jan Domanski <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class NullTransport extends AbstractTransport |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Response you want to get from the transport |
21
|
|
|
* |
22
|
|
|
* @var Response Response |
23
|
|
|
*/ |
24
|
|
|
protected $_response = null; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Set response object the transport returns |
28
|
|
|
* |
29
|
|
|
* @param \Elastica\Response $response |
|
|
|
|
30
|
|
|
* |
31
|
|
|
* @return $this |
32
|
|
|
*/ |
33
|
|
|
public function getResponse() |
34
|
|
|
{ |
35
|
|
|
return $this->_response; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Set response object the transport returns |
40
|
|
|
* |
41
|
|
|
* @param \Elastica\Response $response |
42
|
|
|
* |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function setResponse(Response $response) |
46
|
|
|
{ |
47
|
|
|
$this->_response = $response; |
48
|
|
|
return $this->_response; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Generate an example response object |
53
|
|
|
* |
54
|
|
|
* @param array $params Hostname, port, path, ... |
55
|
|
|
* |
56
|
|
|
* @return \Elastica\Response $response |
57
|
|
|
*/ |
58
|
|
|
public function generateDefaultResponse(array $params) |
59
|
|
|
{ |
60
|
|
|
$response = [ |
61
|
|
|
'took' => 0, |
62
|
|
|
'timed_out' => false, |
63
|
|
|
'_shards' => [ |
64
|
|
|
'total' => 0, |
65
|
|
|
'successful' => 0, |
66
|
|
|
'failed' => 0, |
67
|
|
|
], |
68
|
|
|
'hits' => [ |
69
|
|
|
'total' => 0, |
70
|
|
|
'max_score' => null, |
71
|
|
|
'hits' => [], |
72
|
|
|
], |
73
|
|
|
'params' => $params, |
74
|
|
|
]; |
75
|
|
|
return new Response(JSON::stringify($response)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Null transport. |
80
|
|
|
* |
81
|
|
|
* @param \Elastica\Request $request |
82
|
|
|
* @param array $params Hostname, port, path, ... |
83
|
|
|
* |
84
|
|
|
* @return \Elastica\Response Response empty object |
85
|
|
|
*/ |
86
|
|
|
public function exec(Request $request, array $params) |
87
|
|
|
{ |
88
|
|
|
$response = $this->getResponse(); |
89
|
|
|
|
90
|
|
|
if (!$response) { |
91
|
|
|
$response = $this->generateDefaultResponse($params); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $response; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.