|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LE_ACME2\Exception; |
|
4
|
|
|
|
|
5
|
|
|
use LE_ACME2\Connector\RawResponse; |
|
6
|
|
|
|
|
7
|
|
|
class InvalidResponse extends AbstractException { |
|
8
|
|
|
|
|
9
|
|
|
const RESPONSE_STATUS_TYPE_ERROR_SERVER_INTERNAL = 'urn:ietf:params:acme:error:serverInternal'; |
|
10
|
|
|
const RESPONSE_STATUS_TYPE_ERROR_MALFORMED = 'urn:ietf:params:acme:error:malformed'; |
|
11
|
|
|
|
|
12
|
|
|
private $_rawResponse; |
|
13
|
|
|
private $_responseStatus; |
|
14
|
|
|
private $_responseStatusType; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(RawResponse $rawResponse, string $responseStatus = null) { |
|
17
|
|
|
|
|
18
|
|
|
$this->_rawResponse = $rawResponse; |
|
19
|
|
|
$this->_responseStatus = $responseStatus; |
|
20
|
|
|
|
|
21
|
|
|
if($responseStatus === '') { |
|
22
|
|
|
$responseStatus = 'Unknown response status'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
if(isset($this->_rawResponse->body['type'])) { |
|
26
|
|
|
$responseStatus = $this->_responseStatusType = $this->_rawResponse->body['type']; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if(isset($this->_rawResponse->body['detail'])) { |
|
30
|
|
|
$responseStatus .= ' - ' . $this->_rawResponse->body['detail']; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
parent::__construct('Invalid response received: ' . $responseStatus); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getRawResponse() : RawResponse { |
|
37
|
|
|
return $this->_rawResponse; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getResponseStatus() : ?string { |
|
41
|
|
|
return $this->_responseStatus; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getResponseStatusType() : ?string { |
|
45
|
|
|
return $this->_responseStatusType; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getResponseStatusDetail() : ?string { |
|
49
|
|
|
|
|
50
|
|
|
if(isset($this->_rawResponse->body['detail'])) { |
|
51
|
|
|
return $this->_rawResponse->body['detail']; |
|
52
|
|
|
} |
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
} |