-
Notifications
You must be signed in to change notification settings - Fork 11
/
ErrorResponse.php
84 lines (71 loc) · 1.48 KB
/
ErrorResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace MABI;
class ErrorResponse
{
/**
* @var string
*/
protected $message;
/**
* @var int
*/
protected $httpcode;
/**
* @var int
*/
protected $code;
/**
* @var array
*/
protected $replacementTokens = array();
/**
* @var array
*/
protected $replacementValues = array();
/**
* @param string $message
* @param int $httpcode
* @param int|null $code
*/
function __construct($message, $httpcode, $code = null)
{
$this->message = $message;
$this->httpcode = $httpcode;
$this->code = $code;
}
public static function FromArray($array)
{
if (!isset($array['message'])) throw new \Exception('Invalid ErrorResponse Array. Must contain a message');
return $newErrorResponse = new ErrorResponse($array['message'],
$array['httpcode'],
isset($array['code']) ? $array['code'] : null);
}
/**
* @return int
*/
public function getCode()
{
return $this->code;
}
/**
* @return int
*/
public function getHttpcode()
{
return $this->httpcode;
}
/**
* @return string
*/
public function getMessage()
{
return $this->message;
}
public function getFormattedMessage($replacementArray = array())
{
if (!empty($replacementArray)) {
return str_replace(array_keys($replacementArray), array_values($replacementArray), $this->getMessage());
}
return str_replace($this->replacementTokens, $this->replacementValues, $this->getMessage());
}
}