| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\OpenIDClient; |
| 6 |
|
| 7 |
use Facile\OpenIDClient\Exception\InvalidArgumentException; |
| 8 |
use JsonException; |
| 9 |
use Psr\Http\Message\ResponseInterface; |
| 10 |
|
| 11 |
use function is_array; |
| 12 |
use function json_decode; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
function parse_metadata_response(ResponseInterface $response, ?int $expectedCode = null): array |
| 22 |
{ |
| 23 |
check_server_response($response, $expectedCode); |
| 24 |
|
| 25 |
try { |
| 26 |
|
| 27 |
$data = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR); |
| 28 |
} catch (JsonException $e) { |
| 29 |
throw new InvalidArgumentException('Invalid metadata content', 0, $e); |
| 30 |
} |
| 31 |
|
| 32 |
if (! is_array($data)) { |
| 33 |
throw new InvalidArgumentException('Invalid metadata content'); |
| 34 |
} |
| 35 |
|
| 36 |
return $data; |
| 37 |
} |