diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5db0ad09b3..eb9cfb523f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,7 +20,7 @@ updates: - "github_actions" - package-ecosystem: "npm" - directory: "/" + directory: "/www/scripts/" schedule: interval: "daily" commit-message: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cf77ee245f..be5ad59b5f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: - name: Get changed python files id: changed-files - uses: tj-actions/changed-files@v45 + uses: tj-actions/changed-files@v46 with: files: "**/*.py" diff --git a/CHANGELOG.md b/CHANGELOG.md index f524323106..16d4118d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ backwards-incompatible changes that will affect existing usage. +## 11.1.0 - 2025-03-24 + +- Add methods like Curl::setGet() for each HTTP request method ([#936](https://github.com/php-curl-class/php-curl-class/pull/936)) + ## 11.0.5 - 2025-03-11 - Fix PHPStan static analysis errors ([#929](https://github.com/php-curl-class/php-curl-class/pull/929)) diff --git a/README.md b/README.md index 78d47a8ab3..c5b8c66a22 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![](https://img.shields.io/github/license/php-curl-class/php-curl-class.svg?style=for-the-badge)](https://github.com/php-curl-class/php-curl-class/blob/master/LICENSE) [![](https://img.shields.io/github/actions/workflow/status/php-curl-class/php-curl-class/ci.yml?style=for-the-badge&label=build&branch=master)](https://github.com/php-curl-class/php-curl-class/actions/workflows/ci.yml) [![](https://img.shields.io/github/actions/workflow/status/php-curl-class/php-curl-class/release.yml?style=for-the-badge&label=release&branch=master)](https://github.com/php-curl-class/php-curl-class/releases/) +[![](https://img.shields.io/github/actions/workflow/status/php-curl-class/php-curl-class/dependabot/dependabot-updates?style=for-the-badge&label=Dependabot&branch=master)](https://github.com/php-curl-class/php-curl-class/actions/workflows/dependabot/dependabot-updates) [![](https://img.shields.io/packagist/dt/php-curl-class/php-curl-class.svg?style=for-the-badge)](https://github.com/php-curl-class/php-curl-class/releases/) PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs. @@ -199,6 +200,7 @@ More examples are available under [/examples](https://github.com/php-curl-class/ Curl::__construct($base_url = null, $options = []) Curl::__destruct() Curl::__get($name) +Curl::__isset($name) Curl::afterSend($callback) Curl::attemptRetry() Curl::beforeSend($callback) @@ -278,10 +280,13 @@ Curl::setDefaultJsonDecoder() Curl::setDefaultTimeout() Curl::setDefaultUserAgent() Curl::setDefaultXmlDecoder() +Curl::setDelete($url, $query_parameters = [], $data = []) Curl::setDigestAuthentication($username, $password = '') Curl::setFile($file) Curl::setFollowLocation($follow_location = true) Curl::setForbidReuse($forbid_reuse = true) +Curl::setGet($url, $data = []) +Curl::setHead($url, $data = []) Curl::setHeader($key, $value) Curl::setHeaders($headers) Curl::setInterface($interface) @@ -289,18 +294,23 @@ Curl::setJsonDecoder($mixed) Curl::setMaxFilesize($bytes) Curl::setMaximumRedirects($maximum_redirects) Curl::setOpt($option, $value) +Curl::setOptions($url, $data = []) Curl::setOpts($options) +Curl::setPatch($url, $data = []) Curl::setPort($port) +Curl::setPost($url, $data = '', $follow_303_with_post = false) Curl::setProtocols($protocols) Curl::setProxy($proxy, $port = null, $username = null, $password = null) Curl::setProxyAuth($auth) Curl::setProxyTunnel($tunnel = true) Curl::setProxyType($type) +Curl::setPut($url, $data = []) Curl::setRange($range) Curl::setRedirectProtocols($redirect_protocols) Curl::setReferer($referer) Curl::setReferrer($referrer) Curl::setRetry($mixed) +Curl::setSearch($url, $data = []) Curl::setStop($callback = null) Curl::setTimeout($seconds) Curl::setUrl($url, $mixed_data = '') diff --git a/examples/multi_curl_add_curl.php b/examples/multi_curl_add_curl.php index f932205a39..be5b809c33 100644 --- a/examples/multi_curl_add_curl.php +++ b/examples/multi_curl_add_curl.php @@ -11,23 +11,19 @@ }); $curl_1 = new Curl(); -$curl_1->setOpt(CURLOPT_POST, true); -$curl_1->setOpt(CURLOPT_POSTFIELDS, [ +$curl_1->setPost('https://httpbin.org/post', [ 'to' => 'alice', 'subject' => 'hi', 'body' => 'hi Alice', ]); -$curl_1->setUrl('https://httpbin.org/post'); $multi_curl->addCurl($curl_1); $curl_2 = new Curl(); -$curl_2->setOpt(CURLOPT_POST, true); -$curl_2->setOpt(CURLOPT_POSTFIELDS, [ +$curl_2->setPost('https://httpbin.org/post', [ 'to' => 'bob', 'subject' => 'hi', 'body' => 'hi Bob', ]); -$curl_2->setUrl('https://httpbin.org/post'); $multi_curl->addCurl($curl_2); $multi_curl->start(); diff --git a/examples/multi_curl_add_curl_low_level.php b/examples/multi_curl_add_curl_low_level.php new file mode 100644 index 0000000000..f932205a39 --- /dev/null +++ b/examples/multi_curl_add_curl_low_level.php @@ -0,0 +1,33 @@ +complete(function ($instance) { + echo 'call to "' . $instance->url . '" completed.' . "\n"; +}); + +$curl_1 = new Curl(); +$curl_1->setOpt(CURLOPT_POST, true); +$curl_1->setOpt(CURLOPT_POSTFIELDS, [ + 'to' => 'alice', + 'subject' => 'hi', + 'body' => 'hi Alice', +]); +$curl_1->setUrl('https://httpbin.org/post'); +$multi_curl->addCurl($curl_1); + +$curl_2 = new Curl(); +$curl_2->setOpt(CURLOPT_POST, true); +$curl_2->setOpt(CURLOPT_POSTFIELDS, [ + 'to' => 'bob', + 'subject' => 'hi', + 'body' => 'hi Bob', +]); +$curl_2->setUrl('https://httpbin.org/post'); +$multi_curl->addCurl($curl_2); + +$multi_curl->start(); diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 6027cd6187..d429ab1d25 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -6,7 +6,7 @@ class Curl extends BaseCurl { - public const VERSION = '11.0.5'; + public const VERSION = '11.1.0'; public const DEFAULT_TIMEOUT = 30; public $curl = null; @@ -275,6 +275,12 @@ private function progressInternal($callback) * @return mixed Returns the value provided by exec. */ public function delete($url, $query_parameters = [], $data = []) + { + $this->setDelete($url, $query_parameters, $data); + return $this->exec(); + } + + public function setDelete($url, $query_parameters = [], $data = []) { if (is_array($url)) { $data = $query_parameters; @@ -295,7 +301,6 @@ public function delete($url, $query_parameters = [], $data = []) if (!empty($data)) { $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data)); } - return $this->exec(); } /** @@ -605,6 +610,12 @@ public function execDone() * @return mixed Returns the value provided by exec. */ public function get($url, $data = []) + { + $this->setGet($url, $data); + return $this->exec(); + } + + public function setGet($url, $data = []) { if (is_array($url)) { $data = $url; @@ -613,7 +624,6 @@ public function get($url, $data = []) $this->setUrl($url, $data); $this->setOptInternal(CURLOPT_CUSTOMREQUEST, 'GET'); $this->setOptInternal(CURLOPT_HTTPGET, true); - return $this->exec(); } /** @@ -642,6 +652,12 @@ public function getInfo($opt = null) * @return mixed Returns the value provided by exec. */ public function head($url, $data = []) + { + $this->setHead($url, $data); + return $this->exec(); + } + + public function setHead($url, $data = []) { if (is_array($url)) { $data = $url; @@ -650,7 +666,6 @@ public function head($url, $data = []) $this->setUrl($url, $data); $this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD'); $this->setOpt(CURLOPT_NOBODY, true); - return $this->exec(); } /** @@ -661,6 +676,12 @@ public function head($url, $data = []) * @return mixed Returns the value provided by exec. */ public function options($url, $data = []) + { + $this->setOptions($url, $data); + return $this->exec(); + } + + public function setOptions($url, $data = []) { if (is_array($url)) { $data = $url; @@ -668,7 +689,6 @@ public function options($url, $data = []) } $this->setUrl($url, $data); $this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS'); - return $this->exec(); } /** @@ -679,6 +699,12 @@ public function options($url, $data = []) * @return mixed Returns the value provided by exec. */ public function patch($url, $data = []) + { + $this->setPatch($url, $data); + return $this->exec(); + } + + public function setPatch($url, $data = []) { if (is_array($url)) { $data = $url; @@ -692,7 +718,6 @@ public function patch($url, $data = []) $this->setUrl($url); $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH'); $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data)); - return $this->exec(); } /** @@ -722,6 +747,12 @@ public function patch($url, $data = []) * [3] http://php.net/ChangeLog-5.php#5.5.11 */ public function post($url, $data = '', $follow_303_with_post = false) + { + $this->setPost($url, $data, $follow_303_with_post); + return $this->exec(); + } + + public function setPost($url, $data = '', $follow_303_with_post = false) { if (is_array($url)) { $follow_303_with_post = (bool)$data; @@ -746,7 +777,6 @@ public function post($url, $data = '', $follow_303_with_post = false) $this->setOpt(CURLOPT_POST, true); $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data)); - return $this->exec(); } /** @@ -757,6 +787,12 @@ public function post($url, $data = '', $follow_303_with_post = false) * @return mixed Returns the value provided by exec. */ public function put($url, $data = []) + { + $this->setPut($url, $data); + return $this->exec(); + } + + public function setPut($url, $data = []) { if (is_array($url)) { $data = $url; @@ -773,7 +809,6 @@ public function put($url, $data = []) if (!empty($put_data)) { $this->setOpt(CURLOPT_POSTFIELDS, $put_data); } - return $this->exec(); } /** @@ -784,6 +819,12 @@ public function put($url, $data = []) * @return mixed Returns the value provided by exec. */ public function search($url, $data = []) + { + $this->setSearch($url, $data); + return $this->exec(); + } + + public function setSearch($url, $data = []) { if (is_array($url)) { $data = $url; @@ -800,7 +841,6 @@ public function search($url, $data = []) if (!empty($put_data)) { $this->setOpt(CURLOPT_POSTFIELDS, $put_data); } - return $this->exec(); } /** diff --git a/tests/run_phpunit.sh b/tests/run_phpunit.sh index 40060d73fb..46d1e1c037 100755 --- a/tests/run_phpunit.sh +++ b/tests/run_phpunit.sh @@ -74,13 +74,13 @@ export PHP_CURL_CLASS_TEST_MODE_ENABLED="yes" # Start test servers. Run servers on different ports to allow simultaneous # requests without blocking. server_count=7 -declare -A pids -for i in $(seq 0 $(("${server_count}" - 1))); do +pids=() +for i in $(seq 0 "$(echo "${server_count} - 1" | bc)"); do port=8000 (( port += $i )) php -S "127.0.0.1:${port}" server.php &> /dev/null & - pids["${i}"]="${!}" + pids+=("${!}") done # Determine which phpunit to use. diff --git a/www/scripts/package.json b/www/scripts/package.json index 20a3e12939..43c0c0963d 100644 --- a/www/scripts/package.json +++ b/www/scripts/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "prismjs": "^1.29.0" + "prismjs": "^1.30.0" } }