-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] OOP API for cURL extension #13394
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
Open
sgolemon
wants to merge
8
commits into
php:master
Choose a base branch
from
sgolemon:curli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b47fca6
Provide OOP interface to cURL extension
sgolemon-corp ab3454f
Make CURLOPT_RETURNTRANSFER the default for OOP interface
sgolemon-corp c3d402c
Add missing stub
sgolemon-corp f2ac5cc
Make CurlHandle::exec() throw on failure
sgolemon-corp 30551d8
Add tests I forgot to stage
sgolemon-corp 9251bad
More tests
sgolemon-corp a4612ba
more tests...
sgolemon-corp 3abd613
more tests
sgolemon-corp 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3553,12 +3553,80 @@ | |||||
*/ | ||||||
const CURLOPT_SAFE_UPLOAD = UNKNOWN; | ||||||
|
||||||
/** | ||||||
* @strict-properties | ||||||
*/ | ||||||
class CurlException extends \Exception {}; | ||||||
|
||||||
/** | ||||||
* @strict-properties | ||||||
*/ | ||||||
class CurlHandleException extends \CurlException {}; | ||||||
|
||||||
/** | ||||||
* @strict-properties | ||||||
*/ | ||||||
class CurlMultiException extends \CurlException {}; | ||||||
|
||||||
/** | ||||||
* @strict-properties | ||||||
*/ | ||||||
class CurlShareException extends \CurlException {}; | ||||||
|
||||||
/** | ||||||
* @strict-properties | ||||||
* @not-serializable | ||||||
*/ | ||||||
final class CurlHandle | ||||||
{ | ||||||
public function __construct(?string $uri = null) {} | ||||||
|
||||||
/** @alias curl_errno */ | ||||||
public function errno(): int {} | ||||||
|
||||||
/** @alias curl_error */ | ||||||
public function error(): string {} | ||||||
|
||||||
/** @alias curl_strerror */ | ||||||
static public function strerror(int $code): string {} | ||||||
|
||||||
/** @alias curl_escape */ | ||||||
public function escape(string $str): string {} | ||||||
|
||||||
/** @alias curl_unescape */ | ||||||
public function unescape(string $str): string {} | ||||||
|
||||||
/** | ||||||
* If CURLOPT_RETURNTRANSFER is True, returns the result on success, | ||||||
* otherwise returns True, and the result will be output. | ||||||
* @throws CurlHandleException on failure. | ||||||
*/ | ||||||
public function exec(): string|true {} | ||||||
|
||||||
/** @alias curl_pause */ | ||||||
public function pause(int $flags): int {} | ||||||
|
||||||
/** @alias curl_reset */ | ||||||
public function reset(): void {} | ||||||
|
||||||
/** @alias curl_getinfo */ | ||||||
public function getInfo(?int $option = null): mixed {} | ||||||
|
||||||
#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */ | ||||||
/** @alias curl_upkeep */ | ||||||
public function upkeep(): bool {} | ||||||
#endif | ||||||
|
||||||
/** | ||||||
* Varies from curl_setopt() to allow fluent chaining. | ||||||
* @throws CurlHandleException | ||||||
*/ | ||||||
public function setOpt(int $option, mixed $value): \CurlHandle {} | ||||||
/** | ||||||
* Returns self to match setOpt() behavior. | ||||||
* @throws CurlHandleException | ||||||
*/ | ||||||
public function setOptArray(array $option): \CurlHandle {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same as in curl_setopt_array |
||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -3567,6 +3635,53 @@ final class CurlHandle | |||||
*/ | ||||||
final class CurlMultiHandle | ||||||
{ | ||||||
/** | ||||||
* Returns self for fluent calling. | ||||||
* @throws CurlException. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be CurlMultiException (and in methods below)? |
||||||
*/ | ||||||
public function addHandle(\CurlHandle $handle): \CurlMultiHandle {} | ||||||
|
||||||
/** | ||||||
* Returns self for fluent calling. | ||||||
* @throws CurlException. | ||||||
*/ | ||||||
public function removeHandle(\CurlHandle $handle): \CurlMultiHandle {} | ||||||
|
||||||
/** | ||||||
* Returns self for fluent calling. | ||||||
* @throws CurlException. | ||||||
*/ | ||||||
public function setOpt(int $option, mixed $value): \CurlMultiHandle {} | ||||||
|
||||||
/** @alias curl_multi_errno */ | ||||||
public function errno(): int {} | ||||||
|
||||||
/** @alias curl_multi_error */ | ||||||
public function error(): ?string {} | ||||||
|
||||||
/** @alias curl_multi_strerror */ | ||||||
public function strerror(int $error_code): ?string {} | ||||||
|
||||||
/** | ||||||
* Returns TRUE if still running, FALSE otherwise. | ||||||
* @param int $still_running | ||||||
* @throws CurlException. | ||||||
*/ | ||||||
public function exec(&$still_running): bool {} | ||||||
|
||||||
/** @alias curl_multi_getcontent */ | ||||||
static public function getContent(\CurlHandle $handle): ?string {} | ||||||
|
||||||
/** | ||||||
* @alias curl_multi_info_read | ||||||
* @param int $queued_messages | ||||||
* @return array<string, int|object>|false | ||||||
* @refcount 1 | ||||||
*/ | ||||||
public function infoRead(&$queued_messages = null): array|false {} | ||||||
|
||||||
/** @alias curl_multi_select */ | ||||||
public function select(float $timeout = 1.0): int {} | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -3575,6 +3690,17 @@ final class CurlMultiHandle | |||||
*/ | ||||||
final class CurlShareHandle | ||||||
{ | ||||||
|
||||||
/** @alias curl_share_errno */ | ||||||
public function errno(): int {} | ||||||
|
||||||
/** @alias curl_share_error */ | ||||||
public function error(): ?string {} | ||||||
|
||||||
/** @alias curl_share_strerror */ | ||||||
static public function strerror(): ?string {} | ||||||
|
||||||
public function setOpt(int $option, mixed $value): \CurlShareHandle {} | ||||||
} | ||||||
|
||||||
function curl_close(CurlHandle $handle): void {} | ||||||
|
@@ -3615,6 +3741,8 @@ function curl_multi_close(CurlMultiHandle $multi_handle): void {} | |||||
|
||||||
function curl_multi_errno(CurlMultiHandle $multi_handle): int {} | ||||||
|
||||||
function curl_multi_error(CurlMultiHandle $multi_handle): ?string {} | ||||||
|
||||||
/** @param int $still_running */ | ||||||
function curl_multi_exec(CurlMultiHandle $multi_handle, &$still_running): int {} | ||||||
|
||||||
|
@@ -3657,6 +3785,8 @@ function curl_share_setopt(CurlShareHandle $share_handle, int $option, mixed $va | |||||
/** @refcount 1 */ | ||||||
function curl_share_strerror(int $error_code): ?string {} | ||||||
|
||||||
function curl_share_error(CurlShareHandle $share_handle): ?string {} | ||||||
|
||||||
/** @refcount 1 */ | ||||||
function curl_strerror(int $error_code): ?string {} | ||||||
|
||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is directly specifying current behaviour, but I wish the return wasn't ambigious based on the current option.