1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fhp\Dialog\Exception; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class FailedRequestException. |
7
|
|
|
* |
8
|
|
|
* Transforms HBCI error to exception. |
9
|
|
|
* |
10
|
|
|
* @package Fhp\Dialog\Exception |
11
|
|
|
*/ |
12
|
|
|
class FailedRequestException extends \Exception |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected $summary = array(); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
protected $responseCode = 0; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $responseMessage; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* FailedRequestException constructor. |
31
|
|
|
* |
32
|
|
|
* @param array $summary |
33
|
|
|
*/ |
34
|
|
|
public function __construct(array $summary) |
35
|
|
|
{ |
36
|
|
|
$this->summary = $summary; |
37
|
|
|
$keys = array_keys($summary); |
38
|
|
|
|
39
|
|
|
$this->responseCode = 0; |
40
|
|
|
$this->responseMessage = 'Unknown error'; |
41
|
|
|
|
42
|
|
|
if (count($summary) == 1) { |
43
|
|
|
$this->responseCode = (int) $keys[0]; |
44
|
|
|
$this->responseMessage = array_shift($summary); |
45
|
|
|
} elseif (count($summary) > 1) { |
46
|
|
|
foreach ($summary as $scode => $smsg) { |
47
|
|
|
if (0 === strpos($smsg, '*')) { |
48
|
|
|
$this->responseCode = (int) $scode; |
49
|
|
|
$this->responseMessage = substr($smsg, 1); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
parent::__construct('Request Failed: ' . $this->responseMessage, $this->responseCode); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function getCodes() |
61
|
|
|
{ |
62
|
|
|
return array_keys($this->summary); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function getSummary() |
69
|
|
|
{ |
70
|
|
|
return $this->summary; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
|
|
public function getResponseCode() |
77
|
|
|
{ |
78
|
|
|
return $this->responseCode; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getResponseMessage() |
85
|
|
|
{ |
86
|
|
|
return $this->responseMessage; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getResponseMessages() |
93
|
|
|
{ |
94
|
|
|
return implode(', ', $this->summary); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|