Curl.php
81 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CURL Transport Exception. |
| 4 | * |
| 5 | * @package Requests\Exceptions |
| 6 | */ |
| 7 | |
| 8 | namespace AmeliaVendor\WpOrg\Requests\Exception\Transport; |
| 9 | |
| 10 | use AmeliaVendor\WpOrg\Requests\Exception\Transport; |
| 11 | |
| 12 | /** |
| 13 | * CURL Transport Exception. |
| 14 | * |
| 15 | * @package Requests\Exceptions |
| 16 | */ |
| 17 | final class Curl extends Transport { |
| 18 | |
| 19 | const EASY = 'cURLEasy'; |
| 20 | const MULTI = 'cURLMulti'; |
| 21 | const SHARE = 'cURLShare'; |
| 22 | |
| 23 | /** |
| 24 | * cURL error code |
| 25 | * |
| 26 | * @var integer |
| 27 | */ |
| 28 | protected $code = -1; |
| 29 | |
| 30 | /** |
| 31 | * Which type of cURL error |
| 32 | * |
| 33 | * EASY|MULTI|SHARE |
| 34 | * |
| 35 | * @var string |
| 36 | */ |
| 37 | protected $type = 'Unknown'; |
| 38 | |
| 39 | /** |
| 40 | * Clear text error message |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | protected $reason = 'Unknown'; |
| 45 | |
| 46 | /** |
| 47 | * Create a new exception. |
| 48 | * |
| 49 | * @param string $message Exception message. |
| 50 | * @param string $type Exception type. |
| 51 | * @param mixed $data Associated data, if applicable. |
| 52 | * @param int $code Exception numerical code, if applicable. |
| 53 | */ |
| 54 | public function __construct($message, $type, $data = null, $code = 0) { |
| 55 | if ($type !== null) { |
| 56 | $this->type = $type; |
| 57 | } |
| 58 | |
| 59 | if ($code !== null) { |
| 60 | $this->code = (int) $code; |
| 61 | } |
| 62 | |
| 63 | if ($message !== null) { |
| 64 | $this->reason = $message; |
| 65 | } |
| 66 | |
| 67 | $message = sprintf('%d %s', $this->code, $this->reason); |
| 68 | parent::__construct($message, $this->type, $data, $this->code); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get the error message. |
| 73 | * |
| 74 | * @return string |
| 75 | */ |
| 76 | public function getReason() { |
| 77 | return $this->reason; |
| 78 | } |
| 79 | |
| 80 | } |
| 81 |