Skip to content

PHP 8: Add support for CurlHandle resource objects #70

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Client implements HttpClient, HttpAsyncClient
/**
* cURL synchronous requests handle.
*
* @var resource|null
* @var resource|\CurlHandle|null
*/
private $handle;

Expand Down
12 changes: 6 additions & 6 deletions src/PromiseCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class PromiseCore
/**
* Create shared core.
*
* @param RequestInterface $request HTTP request.
* @param resource $handle cURL handle.
* @param ResponseBuilder $responseBuilder Response builder.
* @param RequestInterface $request HTTP request.
* @param resource|CurlHandle $handle cURL handle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param resource|CurlHandle $handle cURL handle.
* @param resource|\CurlHandle $handle cURL handle.

or add CurlHandle to the use classes

* @param ResponseBuilder $responseBuilder Response builder.
*
* @throws \InvalidArgumentException If $handle is not a cURL resource.
*/
Expand All @@ -80,7 +80,7 @@ public function __construct(
$handle,
ResponseBuilder $responseBuilder
) {
if (!is_resource($handle)) {
if (!is_resource($handle) && !(is_object($handle) && $handle instanceof \GdImage)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i am confused by the second part, i assume you meant CurlHandle rather than GdImage?

but i think we should make an explicit check for the php version. something like

if (
    PHP_MAJOR_VERSION === 7 && !is_resource($handle)
    || PHP_MAJOR_VERSION > 7 && !$handle instanceof CurlHandle
) {
...

throw new \InvalidArgumentException(
sprintf(
'Parameter $handle expected to be a cURL resource, %s given',
Expand All @@ -89,7 +89,7 @@ public function __construct(
);
}

if (get_resource_type($handle) !== 'curl') {
if (is_resource($handle) && get_resource_type($handle) !== 'curl') {
Copy link
Contributor

Choose a reason for hiding this comment

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

check for php version.

maybe we should split all checks into something like this?

if (PHP_MAJOR_VERSION === 7) {
    both checks
} else {
    class check
}

throw new \InvalidArgumentException(
sprintf(
'Parameter $handle expected to be a cURL resource, %s resource given',
Expand Down Expand Up @@ -138,7 +138,7 @@ public function addOnRejected(callable $callback): void
/**
* Return cURL handle.
*
* @return resource
* @return resource|\CurlHandle
*/
public function getHandle()
{
Expand Down