1 <?php
2
3 /**
4 * ArangoDB PHP Core Client: HTTP Request
5 *
6 * @author Frank Mayer
7 * @copyright Copyright 2013-2015, FRANKMAYER.NET, Athens, Greece
8 */
9
10 namespace frankmayer\ArangoDbPhpCore\Protocols\Http;
11
12
13 /**
14 * Class AbstractHttpRequest
15 *
16 * HTTP-Request object that holds a request. Requests are in some cases not directly passed to the server,
17 * for instance when a request is destined for a batch.
18 *
19 * @package frankmayer\ArangoDbPhpCore\Protocols\Http
20 */
21 abstract class AbstractHttpRequest implements HttpRequestInterface
22 {
23 const METHOD_GET = 'GET';
24 const METHOD_POST = 'POST';
25 const METHOD_PUT = 'PUT';
26 const METHOD_PATCH = 'PATCH';
27 const METHOD_DELETE = 'DELETE';
28 const METHOD_HEAD = 'HEAD';
29 const METHOD_OPTIONS = 'OPTIONS';
30
31 const API_BATCH = '/_api/batch';
32
33
34 /**
35 * @var \frankmayer\ArangoDbPhpCore\Client
36 */
37 public $client;
38 /**
39 * @var \frankmayer\ArangoDbPhpCore\ConnectorInterface
40 */
41 public $connector;
42 /**
43 * @var array
44 */
45 public $connectorOptions = [];
46 /**
47 * @var string The address of the endpoint
48 */
49 public $address;
50 /**
51 * @var string The path-part of the request
52 */
53 public $path;
54 /**
55 * @var string The Body of the request
56 */
57 public $body;
58 /**
59 * @var array The headers of the request
60 */
61 public $headers = [];
62 /**
63 * @var array The options of the request
64 */
65 public $options = [];
66 /**
67 * @var string The type of the request
68 */
69 public $type;
70 /**
71 * @var string The method of the request
72 */
73 public $method;
74 /**
75 * @var string The response data as a result of the request
76 */
77 public $response;
78 /**
79 * @var HttpResponseInterface The response-object as a result of the request
80 */
81 public $responseObject;
82 /**
83 * @var object The wrapped handler of communications.
84 */
85 public $handler;
86 /**
87 * @var string The boundary string for batch operations with ArangoDB
88 */
89 public $batchBoundary;
90 /**
91 * @var object flag for if the request is a batch request (this does not include the batchpart requests)
92 */
93 public $batch;
94
95 /**
96 * @param $client
97 */
98 function __construct($client)
99 {
100 $this->client = $client;
101 }
102
103
104 /**
105 * Method to send an HTTP request.
106 * All request should be done through this method. Any async or batch handling is done within this method.
107 *
108 * @return HttpResponse Http Response object
109 */
110 public abstract function send();
111
112
113 /**
114 * Method to an HTTP batch request
115 *
116 * @param array $batchParts
117 * @param string $boundary
118 *
119 * @return mixed
120 */
121
122
123 public abstract function sendBatch($batchParts = [], $boundary = 'XXXbXXX');
124
125
126 /**
127 * @param $urlQueryArray
128 *
129 * @return string
130 */
131 public function buildUrlQuery($urlQueryArray)
132 {
133 $params = [];
134 foreach ($urlQueryArray as $key => $value) {
135 $params[] = $key . '=' . $value;
136 }
137
138 return '?' . implode('&', $params);
139 }
140 }
141