Skip to content

Commit bc05b17

Browse files
authored
Merge pull request #324 from chinfuyang/feature/request-without-query
feat: add `withoutQuery` method to HTTP client
2 parents 6b0ff18 + 891f577 commit bc05b17

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/http-client/src/Request.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ public function withQuery(array $query = []): Request
214214
return $this;
215215
}
216216

217+
public function withoutQuery(array $keys = []): Request
218+
{
219+
$query = $this->query();
220+
foreach ($keys as $key) {
221+
unset($query[$key]);
222+
}
223+
$this->request = $this->request->withUri($this->request->getUri()->withQuery(http_build_query($query)));
224+
225+
return $this;
226+
}
227+
217228
/**
218229
* Get the underlying PSR compliant request instance.
219230
*/

tests/ApiClient/ApiRequestTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,12 @@ public function testWithQuery(): void
183183

184184
$this->assertSame('param1=value1&param2=value2', $request->toPsrRequest()->getUri()->getQuery());
185185
}
186+
187+
public function testWithoutQuery(): void
188+
{
189+
$request = $this->request->withQuery(['param1' => 'value1', 'param2' => 'value2']);
190+
$request->withoutQuery(['param1']);
191+
192+
$this->assertSame('param2=value2', $request->toPsrRequest()->getUri()->getQuery());
193+
}
186194
}

0 commit comments

Comments
 (0)