Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/functions/parse_callback_params.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient;
6
7 use Facile\OpenIDClient\Exception\RuntimeException;
8 use Psr\Http\Message\ServerRequestInterface;
9
10 use function in_array;
11 use function parse_str;
12 use function strtoupper;
13
14 /**
15 * @internal
16 *
17 * @return array<string, mixed>
18 */
19 function parse_callback_params(ServerRequestInterface $serverRequest): array
20 {
21 $method = strtoupper($serverRequest->getMethod());
22
23 if (! in_array($method, ['GET', 'POST'], true)) {
24 throw new RuntimeException('Invalid callback method');
25 }
26
27 if ('POST' === $method) {
28 parse_str((string) $serverRequest->getBody(), $params);
29 } elseif ('' !== $serverRequest->getUri()->getFragment()) {
30 parse_str($serverRequest->getUri()->getFragment(), $params);
31 } else {
32 parse_str($serverRequest->getUri()->getQuery(), $params);
33 }
34
35 /** @var array<string, mixed> $params */
36 return $params;
37 }