Skip to content

Commit be7732c

Browse files
committed
[#566] Support native CurlAdapter facade methods
1 parent f77f520 commit be7732c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/HttpClient/Adapters/CurlAdapter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ public function getUrl(): ?string
284284

285285
public function supportsMethod(string $method): bool
286286
{
287-
return $this->client !== null && method_exists($this->client, $method);
287+
return in_array($method, ['setHeader', 'setHeaders', 'setOpt', 'setOpts'], true)
288+
|| ($this->client !== null && method_exists($this->client, $method));
288289
}
289290

290291
/**
@@ -293,6 +294,10 @@ public function supportsMethod(string $method): bool
293294
*/
294295
public function callMethod(string $method, array $arguments)
295296
{
297+
if (in_array($method, ['setHeader', 'setHeaders', 'setOpt', 'setOpts'], true)) {
298+
return $this->$method(...$arguments);
299+
}
300+
296301
if ($this->client === null) {
297302
return null;
298303
}
@@ -340,7 +345,7 @@ private function parseResponseHeaders(string $rawHeaders): CaseInsensitiveArray
340345
$headers['Status-Line'] = $rawLines[0];
341346

342347
for ($i = 1, $count = count($rawLines); $i < $count; $i++) {
343-
if (strpos($rawLines[$i], ':') === false) {
348+
if (!str_contains($rawLines[$i], ':')) {
344349
continue;
345350
}
346351

tests/Unit/HttpClient/Adapters/CurlAdapterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,13 @@ public function testCurlAdapterSupportsAndCallsVendorMethods(): void
167167
$this->assertFalse($adapter->supportsMethod('missingMethod'));
168168
$this->assertNull($adapter->callMethod('setTimeout', [15]));
169169
}
170+
171+
public function testCurlAdapterSupportsAndCallsNativeFacadeMethods(): void
172+
{
173+
$adapter = new CurlAdapter();
174+
175+
$this->assertTrue($adapter->supportsMethod('setHeaders'));
176+
$this->assertFalse($adapter->supportsMethod('setTimeout'));
177+
$this->assertSame($adapter, $adapter->callMethod('setHeaders', [['Accept' => 'application/json']]));
178+
}
170179
}

0 commit comments

Comments
 (0)