ArangoDB-PHP-Core API Documentation
  • Namespace
  • Class
  • Deprecated

Namespaces

  • frankmayer
    • ArangoDbPhpCore
      • Api
        • Rest
      • Config
      • Connectors
      • Plugins
      • Protocols
        • Http
      • TraitRepository

Classes

  • frankmayer\ArangoDbPhpCore\Api\Rest\Api
  • frankmayer\ArangoDbPhpCore\Api\Rest\Async
  • frankmayer\ArangoDbPhpCore\Api\Rest\Batch
  • frankmayer\ArangoDbPhpCore\Api\Rest\Collection
  • frankmayer\ArangoDbPhpCore\Api\Rest\Database
  • frankmayer\ArangoDbPhpCore\Api\Rest\Document
  • frankmayer\ArangoDbPhpCore\Api\Rest\DocumentBase
  • frankmayer\ArangoDbPhpCore\Api\Rest\Edge
  • frankmayer\ArangoDbPhpCore\Autoloader
  • frankmayer\ArangoDbPhpCore\Client
  • frankmayer\ArangoDbPhpCore\ClientOptions
  • frankmayer\ArangoDbPhpCore\Config\ConnectionOptions
  • frankmayer\ArangoDbPhpCore\Config\DefaultValues
  • frankmayer\ArangoDbPhpCore\Config\Endpoint
  • frankmayer\ArangoDbPhpCore\Config\UpdatePolicy
  • frankmayer\ArangoDbPhpCore\Connectors\AbstractHttpConnector
  • frankmayer\ArangoDbPhpCore\Plugins\Plugin
  • frankmayer\ArangoDbPhpCore\Plugins\PluginManager
  • frankmayer\ArangoDbPhpCore\Plugins\TestPlugin
  • frankmayer\ArangoDbPhpCore\Plugins\TracerPlugin
  • frankmayer\ArangoDbPhpCore\Protocols\Http\AbstractHttpRequest
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpRequest
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpResponse

Interfaces

  • frankmayer\ArangoDbPhpCore\Api\ApiInterface
  • frankmayer\ArangoDbPhpCore\Api\RestApiInterface
  • frankmayer\ArangoDbPhpCore\ClientInterface
  • frankmayer\ArangoDbPhpCore\ConnectorInterface
  • frankmayer\ArangoDbPhpCore\Plugins\PluginInterface
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpConnectorInterface
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpRequestInterface
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpResponseInterface
  • frankmayer\ArangoDbPhpCore\Protocols\RequestInterface
  • frankmayer\ArangoDbPhpCore\Protocols\ResponseInterface

Traits

  • frankmayer\ArangoDbPhpCore\Api\Rest\DocumentTrait
  • frankmayer\ArangoDbPhpCore\Api\Rest\EdgeTrait
  • frankmayer\ArangoDbPhpCore\TraitRepository\ClientLogger

Exceptions

  • frankmayer\ArangoDbPhpCore\ClientException
  • frankmayer\ArangoDbPhpCore\ConnectionException
  • frankmayer\ArangoDbPhpCore\Exception
  • frankmayer\ArangoDbPhpCore\ServerException
  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  * HTTP-Request object that holds a request. Requests are in some cases not directly passed to the server,
 15  * for instance when a request is destined for a batch.
 16  *
 17  * @package frankmayer\ArangoDbPhpCore\Protocols\Http
 18  */
 19 /**
 20  * Class HttpRequest
 21  *
 22  * @package frankmayer\ArangoDbPhpCore\Protocols\Http
 23  */
 24 class HttpRequest extends AbstractHttpRequest implements HttpRequestInterface
 25 {
 26     /**
 27      * @var array $batchparts
 28      */
 29     public $batchParts;
 30     /**
 31      * @var boolean $async
 32      */
 33     public $async;
 34     /**
 35      * @var boolean $batch
 36      */
 37     public $batch;
 38     /**
 39      * @var string $batchBoundary
 40      */
 41     public $batchBoundary;
 42     /**
 43      * @var boolean
 44      * todo: is this still needed?
 45      */
 46     public $isBatchPart202;
 47 
 48 
 49     /**
 50      * Method to send an HTTP request.
 51      * All request should be done through this method. Any async or batch handling is done within this method.
 52      *
 53      * @return HttpResponse Http Response object
 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             //            $this->isBatchPart = true;
 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      * @param array  $batchParts
 93      * @param string $boundary
 94      *
 95      * @return HttpResponseInterface
 96      */
 97     public function sendBatch(
 98         $batchParts = [],
 99         $boundary = 'XXXbXXX'
100     ) {
101         $connector  = $this->client->connector;
102         $this->body = '';
103         /** @var $batchPart HttpResponse */
104         // Reminder... The reason, that at this time the batch-parts are HttpResponses is, because of the quasi "promise" that we have to return immediately
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      * @param string $address
131      */
132     public function setAddress($address)
133     {
134         $this->address = $address;
135     }
136 
137     /**
138      * @return string
139      */
140     public function getAddress()
141     {
142         return $this->address;
143     }
144 
145     /**
146      * @param string $body
147      */
148     public function setBody($body)
149     {
150         $this->body = $body;
151     }
152 
153     /**
154      * @return string
155      */
156     public function getBody()
157     {
158         return $this->body;
159     }
160 
161     /**
162      * @param \frankmayer\ArangoDbPhpCore\Client $client
163      */
164     public function setClient($client)
165     {
166         $this->client = $client;
167     }
168 
169     /**
170      * @return \frankmayer\ArangoDbPhpCore\Client
171      */
172     public function getClient()
173     {
174         return $this->client;
175     }
176 
177     /**
178      * @param \frankmayer\ArangoDbPhpCore\ConnectorInterface $connector
179      */
180     public function setConnector($connector)
181     {
182         $this->connector = $connector;
183     }
184 
185     /**
186      * @return \frankmayer\ArangoDbPhpCore\ConnectorInterface
187      */
188     public function getConnector()
189     {
190         return $this->connector;
191     }
192 
193     /**
194      * @param array $headers
195      */
196     public function setHeaders($headers)
197     {
198         $this->headers = $headers;
199     }
200 
201     /**
202      * @return array
203      */
204     public function getHeaders()
205     {
206         return $this->headers;
207     }
208 
209     /**
210      * @param string $method
211      */
212     public function setMethod($method)
213     {
214         $this->method = $method;
215     }
216 
217     /**
218      * @return string
219      */
220     public function getMethod()
221     {
222         return $this->method;
223     }
224 
225     /**
226      * @param array $options
227      */
228     public function setOptions($options)
229     {
230         $this->options = $options;
231     }
232 
233     /**
234      * @return array
235      */
236     public function getOptions()
237     {
238         return $this->options;
239     }
240 
241     /**
242      * @param string $path
243      */
244     public function setPath($path)
245     {
246         $this->path = $path;
247     }
248 
249     /**
250      * @return string
251      */
252     public function getPath()
253     {
254         return $this->path;
255     }
256 
257     /**
258      * @param string $response
259      */
260     public function setResponse($response)
261     {
262         $this->response = $response;
263     }
264 
265     /**
266      * @return string
267      */
268     public function getResponse()
269     {
270         return $this->response;
271     }
272     // todo 1 Frank Revisit this method and getter/setter
273 
274     //    /**
275     //     * @param \frankmayer\ArangoDbPhpCore\Connectors\ResponseInterface $responseObject
276     //     */
277     //    public function setResponseObject($responseObject)
278     //    {
279     //        $this->responseObject = $responseObject;
280     //    }
281     //
282     //    /**
283     //     * @return \frankmayer\ArangoDbPhpCore\Connectors\ResponseInterface
284     //     */
285     //    public function getResponseObject()
286     //    {
287     //        return $this->responseObject;
288     //    }
289     // todo 1 Frank Revisit this method and getter/setter
290     //    /**
291     //     * @param string $type
292     //     */
293     //    public function setType($type)
294     //    {
295     //        $this->type = $type;
296     //    }
297     //
298     //    /**
299     //     * @return string
300     //     */
301     //    public function getType()
302     //    {
303     //        return $this->type;
304     //    }
305 }
306 
ArangoDB-PHP-Core API Documentation API documentation generated by ApiGen