1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
namespace Elastification\Client\Transport\Thrift; |
19
|
|
|
|
20
|
|
|
use Elasticsearch\Method; |
21
|
|
|
use Elasticsearch\RestRequest; |
22
|
|
|
use Elastification\Client\Transport\TransportRequestInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @package Elastification\Client\Transport\Thrift |
26
|
|
|
* @author Mario Mueller |
27
|
|
|
*/ |
28
|
|
|
class ThriftTransportRequest implements TransportRequestInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var RestRequest |
32
|
|
|
*/ |
33
|
|
|
private $request; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $method The http method to use. |
37
|
|
|
* @param array $vals |
38
|
|
|
*/ |
39
|
2 |
|
function __construct($method, $vals = null) |
|
|
|
|
40
|
|
|
{ |
41
|
2 |
|
$this->request = new RestRequest($vals); |
42
|
2 |
|
$this->request->method = array_flip(Method::$__names)[$method]; |
43
|
2 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $body The raw request body. |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
* @author Mario Mueller |
50
|
|
|
*/ |
51
|
1 |
|
public function setBody($body) |
52
|
|
|
{ |
53
|
1 |
|
$this->request->body = $body; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $path The path according to the Elasticsearch http interface. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
* @author Mario Mueller |
61
|
|
|
*/ |
62
|
1 |
|
public function setPath($path) |
63
|
|
|
{ |
64
|
1 |
|
$this->request->uri = $path; |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return RestRequest |
69
|
|
|
* @author Mario Mueller |
70
|
|
|
*/ |
71
|
1 |
|
public function getWrappedRequest() |
72
|
|
|
{ |
73
|
1 |
|
return $this->request; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param array $params |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
* @author Mario Mueller |
81
|
|
|
*/ |
82
|
1 |
|
public function setQueryParams(array $params) |
83
|
|
|
{ |
84
|
1 |
|
$this->request->parameters = $params; |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.