1 <?php
2 3 4 5 6 7
8
9 namespace frankmayer\ArangoDbPhpCore\Api\Rest;
10
11 use frankmayer\ArangoDbPhpCore\Protocols\Http\AbstractHttpRequest;
12
13
14 15 16 17 18
19 trait DocumentTrait
20 {
21 22 23 24 25 26 27 28
29 public function create(
30 $collection = null,
31 $body = null,
32 $urlQuery = [],
33 $options = []
34 ) {
35
36
37 $request = $this->getRequest();
38 $request->options = $options;
39 $request->body = $body;
40
41 if (is_array($request->body)) {
42 $request->body = json_encode($request->body);
43 }
44
45 $request->path = $this->client->fullDatabasePath . static::API_PATH;
46
47 if (isset($collection)) {
48 $urlQuery = array_merge(
49 $urlQuery ? $urlQuery : [],
50 ['collection' => $collection]
51 );
52 }
53
54 $urlQuery = $request->buildUrlQuery($urlQuery);
55
56 $request->path .= $urlQuery;
57
58 $request->method = static::METHOD_POST;
59
60 return $this->getReturnObject($request);
61 }
62 }
63