| @@ 58-71 (lines=14) @@ | ||
| 55 | * |
|
| 56 | * @throws \Exception If validation fails. Needs a custom exception type. |
|
| 57 | */ |
|
| 58 | protected function validateAndSend($schemaUri, $uri, \JsonSerializable $object) |
|
| 59 | { |
|
| 60 | $payload = json_encode($object); |
|
| 61 | $schema = Dereferencer::draft4()->dereference($schemaUri); |
|
| 62 | $validator = new Validator(json_decode($payload), $schema); |
|
| 63 | ||
| 64 | if ($validator->fails()) { |
|
| 65 | throw new \Exception('Fails validation'); |
|
| 66 | } |
|
| 67 | ||
| 68 | return $this->getClient()->request('POST', $uri, [ |
|
| 69 | 'body' => $payload |
|
| 70 | ]); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||
| @@ 25-40 (lines=16) @@ | ||
| 22 | * |
|
| 23 | * @throws \Exception If validation fails. Needs a custom exception type. |
|
| 24 | */ |
|
| 25 | public function update(BranchObject $branchObject) |
|
| 26 | { |
|
| 27 | $payload = json_encode($branchObject); |
|
| 28 | $schema = Dereferencer::draft4()->dereference(self::UPDATE_SCHEMA); |
|
| 29 | $validator = new Validator(json_decode($payload), $schema); |
|
| 30 | ||
| 31 | if ($validator->fails()) { |
|
| 32 | throw new \Exception('Fails validation'); |
|
| 33 | } |
|
| 34 | ||
| 35 | $result = $this->getClient()->request('POST', self::UPDATE_URI, [ |
|
| 36 | 'body' => $payload |
|
| 37 | ]); |
|
| 38 | ||
| 39 | return $result; |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||