1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Minotaur |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
7
|
|
|
* use this file except in compliance with the License. You may obtain a copy of |
8
|
|
|
* the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations under |
16
|
|
|
* the License. |
17
|
|
|
* |
18
|
|
|
* @copyright 2015-2017 Appertly |
19
|
|
|
* @license Apache-2.0 |
20
|
|
|
*/ |
21
|
|
|
namespace Minotaur\Net\Exception; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Exception for when a server response was not what we were expecting. |
25
|
|
|
*/ |
26
|
|
|
class Unexpected extends \UnexpectedValueException implements \Minotaur\Net\Exception |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var array<string,mixed> The cURL response info |
30
|
|
|
*/ |
31
|
|
|
private $info; |
32
|
|
|
/** |
33
|
|
|
* @var string the response body, or `null` |
34
|
|
|
*/ |
35
|
|
|
private $body; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param $body - The response body |
39
|
|
|
* @param $info - The cURL response info |
40
|
|
|
* @param $msg - The message |
41
|
|
|
* @param $code - The code |
42
|
|
|
* @param $previous - Any nested exception |
43
|
|
|
*/ |
44
|
|
|
public function __construct(?string $body, iterable $info, string $msg, int $code = 0, \Exception $previous = null) |
45
|
|
|
{ |
46
|
|
|
$this->info = is_array($info) ? $info : iterator_to_array($info, true); |
47
|
|
|
$this->body = $body; |
48
|
|
|
parent::__construct($msg, $code, $previous); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Gets the cURL handle info. |
53
|
|
|
* |
54
|
|
|
* @return array<string,mixed> the handle info |
55
|
|
|
*/ |
56
|
|
|
public function getInfo(): array |
57
|
|
|
{ |
58
|
|
|
return $this->info; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Gets the response body. |
63
|
|
|
* |
64
|
|
|
* @return string|null the response body |
65
|
|
|
*/ |
66
|
|
|
public function getBody(): ?string |
67
|
|
|
{ |
68
|
|
|
return $this->body; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|