Curl
云策文档标注
概述
本文档介绍了 WordPress 中的 Curl 类,这是一个用于处理 cURL 传输异常的类,继承自 Transport 类。它定义了异常类型、错误代码和消息,并提供了构造函数和获取错误信息的方法。
关键要点
- Curl 类继承自 Transport 类,用于处理 cURL 相关的传输异常。
- 定义了三个常量:EASY、MULTI 和 SHARE,分别表示 cURL 错误类型。
- 包含属性:$code(错误代码)、$type(错误类型)和 $reason(错误消息)。
- 提供了 __construct 构造函数,用于初始化异常对象,并设置错误代码、类型和消息。
- 提供了 getReason 方法,用于获取错误消息。
代码示例
final class Curl extends Transport {
const EASY = 'cURLEasy';
const MULTI = 'cURLMulti';
const SHARE = 'cURLShare';
protected $code = -1;
protected $type = 'Unknown';
protected $reason = 'Unknown';
public function __construct($message, $type, $data = null, $code = 0) {
if ($type !== null) {
$this->type = $type;
}
if ($code !== null) {
$this->code = (int) $code;
}
if ($message !== null) {
$this->reason = $message;
}
$message = sprintf('%d %s', $this->code, $this->reason);
parent::__construct($message, $this->type, $data, $this->code);
}
public function getReason() {
return $this->reason;
}
}
原文内容
CURL Transport Exception.
Methods
| Name | Description |
|---|---|
| Curl::__construct | Create a new exception. |
| Curl::getReason | Get the error message. |
Source
final class Curl extends Transport {
const EASY = 'cURLEasy';
const MULTI = 'cURLMulti';
const SHARE = 'cURLShare';
/**
* cURL error code
*
* @var integer
*/
protected $code = -1;
/**
* Which type of cURL error
*
* EASY|MULTI|SHARE
*
* @var string
*/
protected $type = 'Unknown';
/**
* Clear text error message
*
* @var string
*/
protected $reason = 'Unknown';
/**
* Create a new exception.
*
* @param string $message Exception message.
* @param string $type Exception type.
* @param mixed $data Associated data, if applicable.
* @param int $code Exception numerical code, if applicable.
*/
public function __construct($message, $type, $data = null, $code = 0) {
if ($type !== null) {
$this->type = $type;
}
if ($code !== null) {
$this->code = (int) $code;
}
if ($message !== null) {
$this->reason = $message;
}
$message = sprintf('%d %s', $this->code, $this->reason);
parent::__construct($message, $this->type, $data, $this->code);
}
/**
* Get the error message.
*
* @return string
*/
public function getReason() {
return $this->reason;
}
}