In the code below, the path of the URL is processed with rtrim and ltrim.
This process trims the "?" at the end, but it cannot be processed when parameters are included, such as /_bulk?timeout=60s.
protected function parseOrFail(array $payload): static {
static::validateInputFields($payload, static::PAYLOAD_FIELDS);
// Checking if request format and endpoint are supported
$this->path = rtrim(ltrim($payload['message']['path_query'], '/'), '?'); # here!
I understand that it currently evaluates endpoints containing parameters such as "sql?mode=raw".
I don't think this implementation is clean.
In the first place, PHP has a parse_url() function, so it may be easier to implement using that function.
And I think it's better to evaluate paths and parameters separately. Also in the future.
$origin = "/_bulk?timeout=60s";
$pathInfo = parse_url($origin);
var_dump($pathInfo);
# array(2) {
# ["path"]=>
# string(6) "/_bulk"
# ["query"]=>
# string(11) "timeout=60s"
}
In the code below, the path of the URL is processed with rtrim and ltrim.
This process trims the "?" at the end, but it cannot be processed when parameters are included, such as /_bulk?timeout=60s.
I understand that it currently evaluates endpoints containing parameters such as "sql?mode=raw".
I don't think this implementation is clean.
In the first place, PHP has a parse_url() function, so it may be easier to implement using that function.
And I think it's better to evaluate paths and parameters separately. Also in the future.