1 <?php
2
3 4 5 6 7 8
9
10 namespace frankmayer\ArangoDbPhpCore\Protocols\Http;
11
12
13 14 15 16 17 18
19 20 21 22 23
24 class HttpRequest extends AbstractHttpRequest implements HttpRequestInterface
25 {
26 27 28
29 public $batchParts;
30 31 32
33 public $async;
34 35 36
37 public $batch;
38 39 40
41 public $batchBoundary;
42 43 44 45
46 public $isBatchPart202;
47
48
49 50 51 52 53 54
55 public function send()
56 {
57 $this->client->notifyPlugins('beforeRequest', $this);
58 if (isset($this->options['async'])) {
59 $async = $this->options['async'];
60 if (is_bool($async)) {
61 $async = var_export($async, true);
62 }
63 $this->headers['x-arango-async'] = $async;
64 }
65
66 if (isset($this->client->arangoDBApiVersion)) {
67 $this->headers['x-arango-version'] = $this->client->arangoDBApiVersion;
68 }
69
70 if (isset($this->options['isBatchPart']) && $this->options['isBatchPart'] === true) {
71
72 $this->address = $this->client->endpoint . $this->path;
73
74 return true;
75 } else {
76 if (isset($this->options) && (!array_key_exists(
77 'isBatchRequest',
78 $this->options
79 ) || (isset($this->options['isBatchRequest']) && $this->options['isBatchRequest'] !== true))
80 ) {
81 $this->headers['Content-Type'] = 'application/json';
82 }
83 $this->address = $this->client->endpoint . $this->path;
84 $this->response = $this->client->connector->request($this);
85 }
86
87 return $this->client->doRequest($this);
88 }
89
90
91 92 93 94 95 96
97 public function sendBatch(
98 $batchParts = [],
99 $boundary = 'XXXbXXX'
100 ) {
101 $connector = $this->client->connector;
102 $this->body = '';
103
104
105 foreach ($batchParts as $contentId => $batchPart) {
106 $this->body .= '--' . $boundary . $connector::HTTP_EOL;
107 $this->body .= 'Content-Type: application/x-arango-batchpart' . $connector::HTTP_EOL;
108 $this->body .= 'Content-Id: ' . ($contentId + 1) . $connector::HTTP_EOL;
109
110 $this->body .= $connector::HTTP_EOL;
111 $this->body .= strtoupper($batchPart->method) . ' ' . $batchPart->path
112 . ' ' . 'HTTP/1.1' . $connector::HTTP_EOL . $connector::HTTP_EOL;
113 $this->body .= $batchPart->body . $connector::HTTP_EOL;
114 }
115 $this->body .= '--' . $boundary . '--' . $connector::HTTP_EOL;
116 $this->path = $this->client->fullDatabasePath . self::API_BATCH;
117 $this->headers['Content-Type'] = 'multipart/form-data; ' . $boundary;
118
119 $this->method = 'post';
120 $this->batch = true;
121 $this->batchBoundary = $boundary;
122 $this->batchParts = $batchParts;
123 $this->responseObject = $this->send();
124
125 return $this->responseObject;
126 }
127
128
129 130 131
132 public function setAddress($address)
133 {
134 $this->address = $address;
135 }
136
137 138 139
140 public function getAddress()
141 {
142 return $this->address;
143 }
144
145 146 147
148 public function setBody($body)
149 {
150 $this->body = $body;
151 }
152
153 154 155
156 public function getBody()
157 {
158 return $this->body;
159 }
160
161 162 163
164 public function setClient($client)
165 {
166 $this->client = $client;
167 }
168
169 170 171
172 public function getClient()
173 {
174 return $this->client;
175 }
176
177 178 179
180 public function setConnector($connector)
181 {
182 $this->connector = $connector;
183 }
184
185 186 187
188 public function getConnector()
189 {
190 return $this->connector;
191 }
192
193 194 195
196 public function setHeaders($headers)
197 {
198 $this->headers = $headers;
199 }
200
201 202 203
204 public function getHeaders()
205 {
206 return $this->headers;
207 }
208
209 210 211
212 public function setMethod($method)
213 {
214 $this->method = $method;
215 }
216
217 218 219
220 public function getMethod()
221 {
222 return $this->method;
223 }
224
225 226 227
228 public function setOptions($options)
229 {
230 $this->options = $options;
231 }
232
233 234 235
236 public function getOptions()
237 {
238 return $this->options;
239 }
240
241 242 243
244 public function setPath($path)
245 {
246 $this->path = $path;
247 }
248
249 250 251
252 public function getPath()
253 {
254 return $this->path;
255 }
256
257 258 259
260 public function setResponse($response)
261 {
262 $this->response = $response;
263 }
264
265 266 267
268 public function getResponse()
269 {
270 return $this->response;
271 }
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305 }
306