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 class DocumentBase extends Api
20 {
21 22 23
24 const API_PATH = '/_api/document';
25
26 27 28 29 30 31 32 33
34 public function replace(
35 $handle,
36 $body,
37 $urlQuery = [],
38 $options = []
39 ) {
40
41 $request = $this->getRequest();
42 $request->options = $options;
43 $request->body = $body;
44
45 if (is_array($request->body)) {
46 $request->body = json_encode($request->body);
47 }
48
49 $request->path = $this->client->fullDatabasePath . static::API_PATH . '/' . $handle;
50
51 $urlQuery = $request->buildUrlQuery($urlQuery);
52
53 $request->path .= $urlQuery;
54
55 $request->method = static::METHOD_PUT;
56
57 return $this->getReturnObject($request);
58 }
59
60 61 62 63 64 65 66 67
68 public function update(
69 $handle,
70 $body,
71 $urlQuery = [],
72 $options = []
73 ) {
74
75 $request = $this->getRequest();
76 $request->options = $options;
77 $request->body = $body;
78
79 if (is_array($request->body)) {
80 $request->body = json_encode($request->body);
81 }
82
83 $request->path = $this->client->fullDatabasePath . static::API_PATH . '/' . $handle;
84
85 $urlQuery = $request->buildUrlQuery($urlQuery);
86
87 $request->path .= $urlQuery;
88
89 $request->method = static::METHOD_PATCH;
90
91 return $this->getReturnObject($request);
92 }
93
94
95 96 97 98 99 100
101 public function getAll(
102 $collection,
103 $options = []
104 ) {
105
106 $request = $this->getRequest();
107 $request->options = $options;
108 $request->path = $this->client->fullDatabasePath . static::API_PATH;
109 $request->path .= '?collection=' . $collection;
110 $request->method = static::METHOD_GET;
111
112 return $this->getReturnObject($request);
113 }
114
115
116 117 118 119 120 121
122 public function get(
123 $handle,
124 $options = []
125 ) {
126
127 $request = $this->getRequest();
128 $request->options = $options;
129 $request->path = $this->client->fullDatabasePath . static::API_PATH . '/' . $handle;
130 $request->method = static::METHOD_GET;
131
132 return $this->getReturnObject($request);
133 }
134
135
136 137 138 139 140 141
142 public function getHeader(
143 $handle,
144 $options = []
145 ) {
146
147 $request = $this->getRequest();
148 $request->options = $options;
149 $request->path = $this->client->fullDatabasePath . static::API_PATH . '/' . $handle;
150 $request->method = static::METHOD_HEAD;
151
152 return $this->getReturnObject($request);
153 }
154
155 156 157 158 159 160
161 public function delete(
162 $handle,
163 $options = []
164 ) {
165
166 $request = $this->getRequest();
167 $request->options = $options;
168 $request->path = $this->client->fullDatabasePath . static::API_PATH . '/' . $handle;
169 $request->method = static::METHOD_DELETE;
170
171 return $this->getReturnObject($request);
172 }
173 }
174