|
10 | 10 | use Domainrobot\Model\Zone; |
11 | 11 | use Domainrobot\Model\ZoneStream; |
12 | 12 | use Domainrobot\Model\Query; |
| 13 | +use Domainrobot\Model\ZoneBasePatchRequest; |
13 | 14 | use Domainrobot\Service\DomainrobotService; |
14 | 15 |
|
15 | 16 | class ZoneService extends DomainrobotService |
@@ -164,6 +165,7 @@ public function list(Query $body = null) |
164 | 165 | $z = new Zone($d); |
165 | 166 | array_push($zones, $z); |
166 | 167 | } |
| 168 | + |
167 | 169 | return $zones; |
168 | 170 | } |
169 | 171 |
|
@@ -201,6 +203,7 @@ public function listAsync(Query $body = null) |
201 | 203 | if ($body != null) { |
202 | 204 | $data = $body->toArray(); |
203 | 205 | } |
| 206 | + |
204 | 207 | return new DomainrobotPromise($this->sendRequest( |
205 | 208 | $this->domainrobotConfig->getUrl() . "/zone/_search", |
206 | 209 | 'POST', |
@@ -301,15 +304,60 @@ public function updateAsync(Zone $body) |
301 | 304 | } else { |
302 | 305 | $name = $body->getOrigin(); |
303 | 306 | } |
| 307 | + |
304 | 308 | if ($body->getVirtualNameServer() === null) { |
305 | 309 | throw new \InvalidArgumentException("Field Zone.virtualNameServer is missing."); |
306 | 310 | } else { |
307 | 311 | $systemNameServer = $body->getVirtualNameServer(); |
308 | 312 | } |
| 313 | + |
309 | 314 | return $this->sendRequest( |
310 | 315 | $this->domainrobotConfig->getUrl() . "/zone/$name/$systemNameServer", |
311 | 316 | 'PUT', |
312 | 317 | ["json" => $body->toArray()] |
313 | 318 | ); |
314 | 319 | } |
| 320 | + |
| 321 | + /** |
| 322 | + * Sends a zone patch request. |
| 323 | + * |
| 324 | + * @param ZoneBasePatchRequest $body |
| 325 | + * @return Zone |
| 326 | + */ |
| 327 | + public function patch(ZoneBasePatchRequest $body) |
| 328 | + { |
| 329 | + $domainrobotPromise = $this->patchAsync($body); |
| 330 | + $domainrobotResult = $domainrobotPromise->wait(); |
| 331 | + |
| 332 | + Domainrobot::setLastDomainrobotResult($domainrobotResult); |
| 333 | + |
| 334 | + return new Zone(ArrayHelper::getValueFromArray($domainrobotResult->getResult(), 'data.0', [])); |
| 335 | + } |
| 336 | + |
| 337 | + /** |
| 338 | + * Sends a zone update request. |
| 339 | + * |
| 340 | + * @param ZoneBasePatchRequest $body |
| 341 | + * @return DomainrobotPromise |
| 342 | + */ |
| 343 | + public function patchAsync(ZoneBasePatchRequest $body) |
| 344 | + { |
| 345 | + if ($body->getOrigin() === null) { |
| 346 | + throw new \InvalidArgumentException("Field Zone.origin is missing."); |
| 347 | + } else { |
| 348 | + $name = $body->getOrigin(); |
| 349 | + } |
| 350 | + |
| 351 | + if ($body->getVirtualNameServer() === null) { |
| 352 | + throw new \InvalidArgumentException("Field Zone.virtualNameServer is missing."); |
| 353 | + } else { |
| 354 | + $systemNameServer = $body->getVirtualNameServer(); |
| 355 | + } |
| 356 | + |
| 357 | + return $this->sendRequest( |
| 358 | + $this->domainrobotConfig->getUrl() . "/zone/$name/$systemNameServer", |
| 359 | + 'PATCH', |
| 360 | + ["json" => $body->toArray()] |
| 361 | + ); |
| 362 | + } |
315 | 363 | } |
0 commit comments