-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Implement new Curl URL Api #8770
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
Changes from 6 commits
1c99720
fd75817
4d6c6c4
7ed8f3f
0dbc408
d6ba23c
550456c
02a3e3f
7c2ecb8
7b15a92
afc4046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,6 +26,27 @@ final class CurlShareHandle | |||||
{ | ||||||
} | ||||||
|
||||||
#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */ | ||||||
/** | ||||||
* @strict-properties | ||||||
* @not-serializable | ||||||
*/ | ||||||
final class CurlUrl implements Stringable | ||||||
{ | ||||||
public function __construct(?string $url = null) {} | ||||||
|
||||||
public function get(int $part, int $flags = 0): string {} | ||||||
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. I think this would be our first chance to get rid of the legacy habit of using integers as options and expecting users to pass (global) constants. We already have enums which would offer a cleaner and easier-to-use API IMO. @iluuu1994
Suggested change
I know doing so would introduce an inconsistency with the rest of ext/curl, but I think we should start the API cleanup somewhere :) 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. Since 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. Sorry but the PR was not up to date. I created a new one with new code but on my repo by mistake adoy#1. I just pushed the new code and applied some of your comments to it since they were still valid. The new PR contains setters and getters instead of a "generic" one. |
||||||
|
||||||
public function set(int $part, string $content, int $flags = 0): void {} | ||||||
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. I would love and would strongly suggest the usage of a wither-style, immutable API. We already have a
Suggested change
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. In the context of $url = new CurlUrl('https://www.php.net');
$ch = curl_init();
curl_setopt($ch, CURLOPT_CURLU, $url);
curl_exec($ch);
$url->set('/downloads');
curl_exec($ch); But your point is still valid. It would be nice to have something like |
||||||
|
||||||
public function __toString(): string {} | ||||||
} | ||||||
|
||||||
final class CurlUrlException extends Exception | ||||||
{ | ||||||
} | ||||||
#endif | ||||||
|
||||||
function curl_close(CurlHandle $handle): void {} | ||||||
|
||||||
/** @refcount 1 */ | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ extern zend_module_entry curl_module_entry; | |
PHP_CURL_API extern zend_class_entry *curl_ce; | ||
PHP_CURL_API extern zend_class_entry *curl_share_ce; | ||
PHP_CURL_API extern zend_class_entry *curl_multi_ce; | ||
PHP_CURL_API extern zend_class_entry *curl_CURLUrl_ce; | ||
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. Nit: it would be slightly more fortunate to follow the snake_case format of the other CE variables, like: 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. There is already inconsistency we also have
So either choice is fine with me but I think this one is a little bit better since we see the classname in it. |
||
PHP_CURL_API extern zend_class_entry *curl_CURLUrlException_ce; | ||
PHP_CURL_API extern zend_class_entry *curl_CURLFile_class; | ||
PHP_CURL_API extern zend_class_entry *curl_CURLStringFile_class; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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'm wondering whether we can/want to declare a property/properties, just like what a normal class would do.