1 | <?php |
||
12 | class Request extends Param |
||
13 | { |
||
14 | const HEAD = 'HEAD'; |
||
15 | const POST = 'POST'; |
||
16 | const PUT = 'PUT'; |
||
17 | const GET = 'GET'; |
||
18 | const DELETE = 'DELETE'; |
||
19 | const DEFAULT_CONTENT_TYPE = 'application/json'; |
||
20 | const NDJSON_CONTENT_TYPE = 'application/x-ndjson'; |
||
21 | |||
22 | /** |
||
23 | * @var \Elastica\Connection |
||
24 | */ |
||
25 | protected $_connection; |
||
26 | |||
27 | /** |
||
28 | * Construct. |
||
29 | * |
||
30 | * @param string $path Request path |
||
31 | * @param string $method OPTIONAL Request method (use const's) (default = self::GET) |
||
32 | * @param array $data OPTIONAL Data array |
||
33 | * @param array $query OPTIONAL Query params |
||
34 | * @param Connection $connection |
||
35 | * @param string $contentType Content-Type sent with this request |
||
36 | * |
||
37 | * @return \Elastica\Request OPTIONAL Connection object |
||
|
|||
38 | */ |
||
39 | public function __construct($path, $method = self::GET, $data = [], array $query = [], Connection $connection = null, $contentType = self::DEFAULT_CONTENT_TYPE) |
||
51 | |||
52 | /** |
||
53 | * Sets the request method. Use one of the for consts. |
||
54 | * |
||
55 | * @param string $method Request method |
||
56 | * |
||
57 | * @return $this |
||
58 | */ |
||
59 | public function setMethod($method) |
||
63 | |||
64 | /** |
||
65 | * Get request method. |
||
66 | * |
||
67 | * @return string Request method |
||
68 | */ |
||
69 | public function getMethod() |
||
73 | |||
74 | /** |
||
75 | * Sets the request data. |
||
76 | * |
||
77 | * @param array $data Request data |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function setData($data) |
||
85 | |||
86 | /** |
||
87 | * Return request data. |
||
88 | * |
||
89 | * @return array Request data |
||
90 | */ |
||
91 | public function getData() |
||
95 | |||
96 | /** |
||
97 | * Sets the request path. |
||
98 | * |
||
99 | * @param string $path Request path |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | public function setPath($path) |
||
107 | |||
108 | /** |
||
109 | * Return request path. |
||
110 | * |
||
111 | * @return string Request path |
||
112 | */ |
||
113 | public function getPath() |
||
117 | |||
118 | /** |
||
119 | * Return query params. |
||
120 | * |
||
121 | * @return array Query params |
||
122 | */ |
||
123 | public function getQuery() |
||
127 | |||
128 | /** |
||
129 | * @param array $query |
||
130 | * |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function setQuery(array $query = []) |
||
137 | |||
138 | /** |
||
139 | * @param \Elastica\Connection $connection |
||
140 | * |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setConnection(Connection $connection) |
||
149 | |||
150 | /** |
||
151 | * Return Connection Object. |
||
152 | * |
||
153 | * @throws Exception\InvalidException If no valid connection was setted |
||
154 | * |
||
155 | * @return \Elastica\Connection |
||
156 | */ |
||
157 | public function getConnection() |
||
165 | |||
166 | /** |
||
167 | * Set the Content-Type of this request. |
||
168 | * |
||
169 | * @param string $contentType |
||
170 | */ |
||
171 | public function setContentType($contentType) |
||
175 | |||
176 | /** |
||
177 | * Get the Content-Type of this request. |
||
178 | */ |
||
179 | public function getContentType() |
||
183 | |||
184 | /** |
||
185 | * Sends request to server. |
||
186 | * |
||
187 | * @return \Elastica\Response Response object |
||
188 | */ |
||
189 | public function send() |
||
196 | |||
197 | /** |
||
198 | * @return array |
||
199 | */ |
||
200 | public function toArray() |
||
209 | |||
210 | /** |
||
211 | * Converts request to curl request format. |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function toString() |
||
219 | |||
220 | /** |
||
221 | * @return string |
||
222 | */ |
||
223 | public function __toString() |
||
227 | } |
||
228 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.