| 1 | <?php |
||
| 2 | namespace Pelmered\LaravelHttpOAuthHelper; |
||
| 3 | |||
| 4 | use Illuminate\Http\Client\Response; |
||
| 5 | |||
| 6 | class UrlHelper |
||
| 7 | { |
||
| 8 | 5 | public static function parseQueryTokenFromResponse(Response $response, string $queryKey = 'token'): ?string |
|
| 9 | { |
||
| 10 | 5 | $uri = $response->effectiveUri(); |
|
| 11 | |||
| 12 | 5 | if (! $uri) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 13 | return null; |
||
| 14 | } |
||
| 15 | |||
| 16 | 5 | return self::parseTokenFromQueryString($response->effectiveUri()?->getQuery(), $queryKey); |
|
|
0 ignored issues
–
show
|
|||
| 17 | } |
||
| 18 | |||
| 19 | 6 | public static function parseQueryTokenFromUrl(string $url, string $queryKey = 'token'): ?string |
|
| 20 | { |
||
| 21 | 6 | $queryString = parse_url($url, PHP_URL_QUERY); |
|
| 22 | |||
| 23 | 6 | if (! $queryString) { |
|
| 24 | 1 | return null; |
|
| 25 | } |
||
| 26 | |||
| 27 | 5 | return self::parseTokenFromQueryString($queryString, $queryKey); |
|
|
0 ignored issues
–
show
|
|||
| 28 | } |
||
| 29 | |||
| 30 | 13 | public static function parseTokenFromQueryString(string $queryString, string $queryKey = 'token'): null|string|array |
|
| 31 | { |
||
| 32 | 13 | parse_str($queryString, $output); |
|
| 33 | |||
| 34 | 13 | if (! isset($output[$queryKey])) { |
|
| 35 | 4 | return null; |
|
| 36 | } |
||
| 37 | |||
| 38 | 9 | return $output[$queryKey] ?? null; |
|
| 39 | } |
||
| 40 | } |
||
| 41 |