From bd64c79d5aa1d7a79eeedd8918902a37b9784309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 30 Mar 2022 12:16:31 +0200 Subject: [PATCH] Request.php : Fix request merge method of data to query --- changelog.md | 2 ++ src/Transport/Request.php | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index accb77f..5179f47 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,8 @@ ### All notable changes to `CRM CLient V2` will be documented in this file. +Fixed : request merge method of data to query (Request.php) + # version 3.0.2 - Regen documentation with php documentor diff --git a/src/Transport/Request.php b/src/Transport/Request.php index 115109b..f89869d 100644 --- a/src/Transport/Request.php +++ b/src/Transport/Request.php @@ -128,8 +128,22 @@ class Request { $this->request = function () { $uri = $this->uri; + // * If query merge query and data, set data to empty. if ($this->method->equals(HttpMethods::get())) { - $uri = sprintf("%s?%s", $uri, http_build_query($this->data)); + // * Merge query in url with Data + $q = \parse_url($uri, \PHP_URL_QUERY) ?? ''; + $q = \strpos($q, '&') !== false ? explode('&', $q) : []; + $query = []; + foreach ($q as $qParam) { + $qParam = explode('=', $qParam, 2); + + $query[$qParam[0]] = $qParam[1]; + } + // * Remove query part. + $uri = strtok($uri, '?'); + // * Append build query + $uri = sprintf("%s?%s", $uri, http_build_query(array_merge($query, $this->data))); + $this->data = []; } $request = new Psr7Request(