1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PostmanGeneratorBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Vincent Chalamon <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PostmanGeneratorBundle\Model; |
13
|
|
|
|
14
|
|
|
use Dunglas\ApiBundle\Api\ResourceInterface; |
15
|
|
|
|
16
|
|
|
class Request |
17
|
|
|
{ |
18
|
|
|
const DATA_MODE_PARAMS = 'params'; |
19
|
|
|
const DATA_MODE_RAW = 'raw'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $url; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $method; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Test[] |
38
|
|
|
*/ |
39
|
|
|
private $tests = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Folder |
43
|
|
|
*/ |
44
|
|
|
private $folder; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $name; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $description = ''; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
private $preRequestScript = ''; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var object |
63
|
|
|
*/ |
64
|
|
|
private $pathVariables; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var array |
68
|
|
|
*/ |
69
|
|
|
private $data = []; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
private $dataMode = self::DATA_MODE_PARAMS; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var array |
78
|
|
|
*/ |
79
|
|
|
private $rawModeData = []; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var int |
83
|
|
|
*/ |
84
|
|
|
private $version = 2; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var string |
88
|
|
|
*/ |
89
|
|
|
private $currentHelper = 'normal'; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var object |
93
|
|
|
*/ |
94
|
|
|
private $helperAttributes; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var int |
98
|
|
|
*/ |
99
|
|
|
private $time; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var bool |
103
|
|
|
*/ |
104
|
|
|
private $fromCollection = false; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var Request |
108
|
|
|
*/ |
109
|
|
|
private $collectionRequest; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var Collection |
113
|
|
|
*/ |
114
|
|
|
private $collection; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var ResourceInterface |
118
|
|
|
*/ |
119
|
|
|
private $resource; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var array |
123
|
|
|
*/ |
124
|
|
|
private $headers = []; |
125
|
|
|
|
126
|
|
|
public function __construct() |
127
|
|
|
{ |
128
|
|
|
$this->pathVariables = new \stdClass(); |
129
|
|
|
$this->helperAttributes = new \stdClass(); |
130
|
|
|
$this->time = time(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getId() |
137
|
|
|
{ |
138
|
|
|
return $this->id; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param string $id |
143
|
|
|
*/ |
144
|
|
|
public function setId($id) |
145
|
|
|
{ |
146
|
|
|
$this->id = $id; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getUrl() |
153
|
|
|
{ |
154
|
|
|
return $this->url; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $url |
159
|
|
|
*/ |
160
|
|
|
public function setUrl($url) |
161
|
|
|
{ |
162
|
|
|
$this->url = $url; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getMethod() |
169
|
|
|
{ |
170
|
|
|
return $this->method; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param string $method |
175
|
|
|
*/ |
176
|
|
|
public function setMethod($method) |
177
|
|
|
{ |
178
|
|
|
$this->method = $method; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return Test[] |
183
|
|
|
*/ |
184
|
|
|
public function getTests() |
185
|
|
|
{ |
186
|
|
|
return $this->tests; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param Test $test |
191
|
|
|
*/ |
192
|
|
|
public function addTest(Test $test) |
193
|
|
|
{ |
194
|
|
|
$this->tests[] = $test; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return Folder |
199
|
|
|
*/ |
200
|
|
|
public function getFolder() |
201
|
|
|
{ |
202
|
|
|
return $this->folder; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param Folder $folder |
207
|
|
|
*/ |
208
|
|
|
public function setFolder(Folder $folder = null) |
209
|
|
|
{ |
210
|
|
|
$this->folder = $folder; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
|
|
public function getName() |
217
|
|
|
{ |
218
|
|
|
return $this->name; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param string $name |
223
|
|
|
*/ |
224
|
|
|
public function setName($name) |
225
|
|
|
{ |
226
|
|
|
$this->name = $name; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return string |
231
|
|
|
*/ |
232
|
|
|
public function getDescription() |
233
|
|
|
{ |
234
|
|
|
return $this->description; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param string $description |
239
|
|
|
*/ |
240
|
|
|
public function setDescription($description) |
241
|
|
|
{ |
242
|
|
|
$this->description = $description; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
public function getPreRequestScript() |
249
|
|
|
{ |
250
|
|
|
return $this->preRequestScript; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param string $preRequestScript |
255
|
|
|
*/ |
256
|
|
|
public function setPreRequestScript($preRequestScript) |
257
|
|
|
{ |
258
|
|
|
$this->preRequestScript = $preRequestScript; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return object |
263
|
|
|
*/ |
264
|
|
|
public function getPathVariables() |
265
|
|
|
{ |
266
|
|
|
return $this->pathVariables; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param object $pathVariables |
271
|
|
|
*/ |
272
|
|
|
public function setPathVariables($pathVariables) |
273
|
|
|
{ |
274
|
|
|
$this->pathVariables = $pathVariables; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @return array |
279
|
|
|
*/ |
280
|
|
|
public function getData() |
281
|
|
|
{ |
282
|
|
|
return $this->data; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @param array $data |
287
|
|
|
*/ |
288
|
|
|
public function setData(array $data) |
289
|
|
|
{ |
290
|
|
|
$this->data = $data; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @return string |
295
|
|
|
*/ |
296
|
|
|
public function getDataMode() |
297
|
|
|
{ |
298
|
|
|
return $this->dataMode; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @param string $dataMode |
303
|
|
|
*/ |
304
|
|
|
public function setDataMode($dataMode) |
305
|
|
|
{ |
306
|
|
|
$this->dataMode = $dataMode; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @return array |
311
|
|
|
*/ |
312
|
|
|
public function getRawModeData() |
313
|
|
|
{ |
314
|
|
|
return $this->rawModeData; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @param array $rawModeData |
319
|
|
|
*/ |
320
|
|
|
public function setRawModeData(array $rawModeData) |
321
|
|
|
{ |
322
|
|
|
$this->rawModeData = $rawModeData; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @return int |
327
|
|
|
*/ |
328
|
|
|
public function getVersion() |
329
|
|
|
{ |
330
|
|
|
return $this->version; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @param int $version |
335
|
|
|
*/ |
336
|
|
|
public function setVersion($version) |
337
|
|
|
{ |
338
|
|
|
$this->version = $version; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return string |
343
|
|
|
*/ |
344
|
|
|
public function getCurrentHelper() |
345
|
|
|
{ |
346
|
|
|
return $this->currentHelper; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* @param string $currentHelper |
351
|
|
|
*/ |
352
|
|
|
public function setCurrentHelper($currentHelper) |
353
|
|
|
{ |
354
|
|
|
$this->currentHelper = $currentHelper; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @return object |
359
|
|
|
*/ |
360
|
|
|
public function getHelperAttributes() |
361
|
|
|
{ |
362
|
|
|
return $this->helperAttributes; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* @param object $helperAttributes |
367
|
|
|
*/ |
368
|
|
|
public function setHelperAttributes($helperAttributes) |
369
|
|
|
{ |
370
|
|
|
$this->helperAttributes = $helperAttributes; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @return int |
375
|
|
|
*/ |
376
|
|
|
public function getTime() |
377
|
|
|
{ |
378
|
|
|
return $this->time; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @param int $time |
383
|
|
|
*/ |
384
|
|
|
public function setTime($time) |
385
|
|
|
{ |
386
|
|
|
$this->time = $time; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* @return bool |
391
|
|
|
*/ |
392
|
|
|
public function isFromCollection() |
393
|
|
|
{ |
394
|
|
|
return $this->fromCollection; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @param bool $fromCollection |
399
|
|
|
*/ |
400
|
|
|
public function setFromCollection($fromCollection) |
401
|
|
|
{ |
402
|
|
|
$this->fromCollection = $fromCollection; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* @return Request |
407
|
|
|
*/ |
408
|
|
|
public function getCollectionRequest() |
409
|
|
|
{ |
410
|
|
|
return $this->collectionRequest; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* @param Request $collectionRequest |
415
|
|
|
*/ |
416
|
|
|
public function setCollectionRequest(Request $collectionRequest) |
417
|
|
|
{ |
418
|
|
|
$this->collectionRequest = $collectionRequest; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @return Collection |
423
|
|
|
*/ |
424
|
|
|
public function getCollection() |
425
|
|
|
{ |
426
|
|
|
return $this->collection; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param Collection $collection |
431
|
|
|
*/ |
432
|
|
|
public function setCollection(Collection $collection) |
433
|
|
|
{ |
434
|
|
|
$this->collection = $collection; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* @return ResourceInterface |
439
|
|
|
*/ |
440
|
|
|
public function getResource() |
441
|
|
|
{ |
442
|
|
|
return $this->resource; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* @param ResourceInterface $resource |
447
|
|
|
*/ |
448
|
|
|
public function setResource(ResourceInterface $resource) |
449
|
|
|
{ |
450
|
|
|
$this->resource = $resource; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* @return array |
455
|
|
|
*/ |
456
|
|
|
public function getHeaders() |
457
|
|
|
{ |
458
|
|
|
return $this->headers; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* @param string $key |
463
|
|
|
* @param string $value |
464
|
|
|
*/ |
465
|
|
|
public function addHeader($key, $value) |
466
|
|
|
{ |
467
|
|
|
$this->headers[$key] = $value; |
468
|
|
|
} |
469
|
|
|
} |
470
|
|
|
|