kukymbr / curl-wrapper
cURL 函数包装器
v0.9.2
2019-11-20 09:02 UTC
Requires
- php: >=7.0.0
- ext-curl: >=7.0
This package is not auto-updated.
Last update: 2024-09-19 08:10:58 UTC
README
cURL PHP 函数 OOP 包装器。
要求
需要 PHP 7.0+。
安装
支持通过 Composer 安装 cURL。
$ composer require kukymbr/curl-wrapper
使用
<?php
use Kukymbr\CurlWrapper\Curl;
// Create Curl instance
$curl = new Curl();
// Set handler options
$curl->setOptArray(
[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
// ... any others CURLOPT_* options
]
);
// Request the "https://example.com?foo-bar" URL
$response = $curl->exec('https://example.com', ['foo' => 'bar']);
// Get the response code
$responseCode = $curl->getResponseCode();
所有 curl_* 函数都以小驼峰命名,例如 $curl->fileCreate()
将调用 curl_file_create
函数。
使用默认值
如果您需要设置自己的默认 cURL 选项,扩展 Curl 并覆盖 _getDefaultOptions
方法
<?php
class MyCurl extends \Kukymbr\CurlWrapper\Curl
{
/**
* Get default cURL options.
*
* @return array
*/
protected function _getDefaultOptions() : array
{
return [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
];
}
}
许可证
MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。