Factories
3 months ago
ApiUri.php
3 months ago
ApiVersion.php
3 months ago
AuthContext.php
3 months ago
AuthState.php
3 months ago
JsonDecoder.php
3 months ago
RequestBuilder.php
3 months ago
RequestExecutor.php
3 months ago
RequestHeaderCollection.php
3 months ago
RetryPolicy.php
3 months ago
JsonDecoder.php
32 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Http; |
| 4 | |
| 5 | use JsonException; |
| 6 | use Give\Vendors\LiquidWeb\LicensingApiClient\Exceptions\DecodingException; |
| 7 | |
| 8 | /** |
| 9 | * Decodes JSON response bodies into arrays for response mappers. |
| 10 | */ |
| 11 | final class JsonDecoder |
| 12 | { |
| 13 | /** |
| 14 | * |
| 15 | * @throws DecodingException |
| 16 | * @return array<array-key, mixed> |
| 17 | */ |
| 18 | public function decode(string $json): array { |
| 19 | try { |
| 20 | $decoded = json_decode($json, true, 512, JSON_THROW_ON_ERROR); |
| 21 | } catch (JsonException $exception) { |
| 22 | throw new DecodingException('Unable to decode JSON response.', 0, $exception); |
| 23 | } |
| 24 | |
| 25 | if (!is_array($decoded)) { |
| 26 | throw new DecodingException('Decoded JSON response must be an array.'); |
| 27 | } |
| 28 | |
| 29 | return $decoded; |
| 30 | } |
| 31 | } |
| 32 |