Skip to content

Commit 6916d10

Browse files
committed
Parse query parameters
1 parent 48771b6 commit 6916d10

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/VerifierServer/Endpoints/HeaderParserTrait.php renamed to src/VerifierServer/Endpoints/ResponseParserTrait.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace VerifierServer\Endpoints;
44

55
/**
6-
* Trait HeaderParserTrait
6+
* Trait ResponseParserTrait
77
*
8-
* Provides functionality to parse HTTP request headers from a raw HTTP request string.
8+
* Provides functionality to parse data from a raw HTTP request string.
99
*
1010
* @package VerifierServer\Endpoints
1111
*/
12-
trait HeaderParserTrait
12+
trait ResponseParserTrait
1313
{
1414
/**
1515
* Parses the headers from a raw HTTP request string.
@@ -23,7 +23,7 @@ trait HeaderParserTrait
2323
* @return array An associative array of headers, where the keys are
2424
* header names and the values are header values.
2525
*/
26-
static function parseHeaders(string $request): array
26+
public static function parseHeaders(string $request): array
2727
{
2828
return array_reduce(
2929
explode(PHP_EOL, $request), fn($carry, $line) =>
@@ -32,4 +32,19 @@ static function parseHeaders(string $request): array
3232
: $carry,
3333
[]);
3434
}
35+
36+
/**
37+
* Parses the query parameters from a given request URL string.
38+
*
39+
* This method extracts the query string from the provided URL,
40+
* parses it into an associative array, and returns the result.
41+
*
42+
* @param string $request The full URL string containing the query parameters.
43+
* @return array An associative array of query parameters.
44+
*/
45+
public static function parseQueryParams(string $request): array
46+
{
47+
parse_str(parse_url($request, PHP_URL_QUERY), $params);
48+
return $params;
49+
}
3550
}

src/VerifierServer/Endpoints/VerifiedEndpoint.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
*/
4747
class VerifiedEndpoint implements EndpointInterface
4848
{
49-
use HeaderParserTrait;
49+
use ResponseParserTrait;
50+
5051
public function __construct(private PersistentState &$state)
5152
{}
5253

0 commit comments

Comments
 (0)