-
Notifications
You must be signed in to change notification settings - Fork 22
Issue/534 http client curl adapters #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
armanist
merged 14 commits into
quantum-php:master
from
armanist:issue/534-http-client-curl-adapters
Jul 15, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f060562
[#534] Add HttpClient adapter skeleton
armanist 4db153e
[#534] Add vendor-backed HttpClient adapters
armanist 0bf45c2
[#534] Route HttpClient through curl adapters
armanist 6de47bb
[#534] Cover HttpClient adapter selection
armanist 9c3a3b3
[#534] Add HttpClient adapter tests
armanist 37fc648
[#534] Document HttpClient adapter refactor
armanist eb5f1b5
[#534] Cover HttpClient factory
armanist 47c91ba
[#534] Wrap multi curl request handles
armanist 33be623
[#534] Preserve zero curl info option
armanist 120777a
[#534] Wrap multi curl callbacks
armanist 48db62c
[#534] Correct HttpClient request assertions
armanist 4d583a9
[#534] Preserve empty HttpClient results
armanist da74cce
[#534] Guard single HttpClient requests
armanist e99f21f
[#534] Preserve zero HttpClient info option
armanist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * Quantum PHP Framework | ||
| * An open-source software development framework for PHP | ||
| * @link https://quantumphp.io | ||
| */ | ||
|
|
||
| namespace Quantum\HttpClient\Adapters; | ||
|
|
||
| use Quantum\HttpClient\Contracts\CurlAdapterInterface; | ||
| use Curl\Curl; | ||
|
|
||
| /** | ||
| * Class CurlAdapter | ||
| * @package Quantum\HttpClient | ||
| */ | ||
| class CurlAdapter implements CurlAdapterInterface | ||
| { | ||
| private Curl $client; | ||
|
|
||
| public function __construct(?Curl $client = null) | ||
| { | ||
| $this->client = $client ?? new Curl(); | ||
| } | ||
|
|
||
| public function setUrl(string $url): CurlAdapterInterface | ||
| { | ||
| $this->client->setUrl($url); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $value | ||
| */ | ||
| public function setOpt(int $option, $value): CurlAdapterInterface | ||
| { | ||
| $this->client->setOpt($option, $value); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int, mixed> $options | ||
| */ | ||
| public function setOpts(array $options): CurlAdapterInterface | ||
| { | ||
| $this->client->setOpts($options); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $value | ||
| */ | ||
| public function setHeader(string $key, $value): CurlAdapterInterface | ||
| { | ||
| $this->client->setHeader($key, $value); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int|string, mixed> $headers | ||
| */ | ||
| public function setHeaders(array $headers): CurlAdapterInterface | ||
| { | ||
| $this->client->setHeaders($headers); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $data | ||
| * @return mixed | ||
| */ | ||
| public function buildPostData($data) | ||
| { | ||
| return $this->client->buildPostData($data); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function start() | ||
| { | ||
| return $this->client->exec(); | ||
| } | ||
|
|
||
| /** | ||
| * @return int|string | ||
| */ | ||
| public function getId() | ||
| { | ||
| return $this->client->getId(); | ||
| } | ||
|
|
||
| public function isError(): bool | ||
| { | ||
| return $this->client->isError(); | ||
| } | ||
|
|
||
| public function getErrorCode(): int | ||
| { | ||
| return $this->client->getErrorCode(); | ||
| } | ||
|
|
||
| public function getErrorMessage(): ?string | ||
| { | ||
| return $this->client->getErrorMessage(); | ||
| } | ||
|
|
||
| /** | ||
| * @return iterable<string, mixed> | ||
| */ | ||
| public function getResponseHeaders(): iterable | ||
| { | ||
| return $this->client->getResponseHeaders(); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getResponseCookies() | ||
| { | ||
| return $this->client->getResponseCookies(); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getResponse() | ||
| { | ||
| return $this->client->getResponse(); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getInfo(?int $option = null) | ||
| { | ||
| return $option !== null ? $this->client->getInfo($option) : $this->client->getInfo(); | ||
| } | ||
|
|
||
| public function getUrl(): ?string | ||
| { | ||
| return $this->client->getUrl(); | ||
| } | ||
|
|
||
| public function supportsMethod(string $method): bool | ||
| { | ||
| return method_exists($this->client, $method); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<mixed> $arguments | ||
| * @return mixed | ||
| */ | ||
| public function callMethod(string $method, array $arguments) | ||
| { | ||
| return $this->client->$method(...$arguments); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * Quantum PHP Framework | ||
| * An open-source software development framework for PHP | ||
| * @link https://quantumphp.io | ||
| */ | ||
|
|
||
| namespace Quantum\HttpClient\Adapters; | ||
|
|
||
| use Quantum\HttpClient\Contracts\MultiCurlAdapterInterface; | ||
| use Curl\MultiCurl; | ||
| use Curl\Curl; | ||
|
|
||
| /** | ||
| * Class MultiCurlAdapter | ||
| * @package Quantum\HttpClient | ||
| */ | ||
| class MultiCurlAdapter implements MultiCurlAdapterInterface | ||
| { | ||
| private MultiCurl $client; | ||
|
|
||
| public function __construct(?MultiCurl $client = null) | ||
| { | ||
| $this->client = $client ?? new MultiCurl(); | ||
| } | ||
|
|
||
| public function complete(callable $callback): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->complete(function (Curl $instance) use ($callback): void { | ||
| $callback(new CurlAdapter($instance)); | ||
| }); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function success(callable $callback): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->success(function (Curl $instance) use ($callback): void { | ||
| $callback(new CurlAdapter($instance)); | ||
| }); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function error(callable $callback): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->error(function (Curl $instance) use ($callback): void { | ||
| $callback(new CurlAdapter($instance)); | ||
| }); | ||
|
|
||
| return $this; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function start() | ||
| { | ||
| return $this->client->start(); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $data | ||
| * @return mixed | ||
| */ | ||
| public function addGet(string $url, array $data = []) | ||
| { | ||
| return $this->wrapCurlResult($this->client->addGet($url, $data)); | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $data | ||
| * @return mixed | ||
| */ | ||
| public function addPost(string $url, $data = '', bool $follow_303_with_post = false) | ||
| { | ||
| return $this->wrapCurlResult($this->client->addPost($url, $data, $follow_303_with_post)); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @param mixed $value | ||
| */ | ||
| public function setHeader(string $key, $value): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->setHeader($key, $value); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int|string, mixed> $headers | ||
| */ | ||
| public function setHeaders(array $headers): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->setHeaders($headers); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $value | ||
| */ | ||
| public function setOpt(int $option, $value): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->setOpt($option, $value); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int, mixed> $options | ||
| */ | ||
| public function setOpts(array $options): MultiCurlAdapterInterface | ||
| { | ||
| $this->client->setOpts($options); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function supportsMethod(string $method): bool | ||
| { | ||
| return method_exists($this->client, $method); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<mixed> $arguments | ||
| * @return mixed | ||
| */ | ||
| public function callMethod(string $method, array $arguments) | ||
| { | ||
| return $this->client->$method(...$arguments); | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $result | ||
| * @return mixed | ||
| */ | ||
| private function wrapCurlResult($result) | ||
| { | ||
| return $result instanceof Curl ? new CurlAdapter($result) : $result; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.