Skip to content

[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
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions ext/curl/curl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

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.

* 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 {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function setOptArray(array $option): \CurlHandle {}
public function setOptArray(array $options): \CurlHandle {}

Same as in curl_setopt_array

}

/**
Expand All @@ -3567,6 +3635,53 @@ final class CurlHandle
*/
final class CurlMultiHandle
{
/**
* Returns self for fluent calling.
* @throws CurlException.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {}
}

/**
Expand All @@ -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 {}
Expand Down Expand Up @@ -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 {}

Expand Down Expand Up @@ -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 {}

Expand Down
Loading