1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Korobovn\CloudPayments\Message\Response; |
6
|
|
|
|
7
|
|
|
use Korobovn\CloudPayments\Message\Response\Model\ModelInterface; |
8
|
|
|
|
9
|
|
|
abstract class AbstractResponse implements ResponseInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var ModelInterface|null |
13
|
|
|
*/ |
14
|
|
|
protected $model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var bool |
18
|
|
|
*/ |
19
|
|
|
protected $success = false; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
protected $message; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var mixed|null |
28
|
|
|
*/ |
29
|
|
|
protected $inner_result; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritDoc} |
33
|
|
|
*/ |
34
|
|
|
public function fillObjectFromArray(array $data): void |
35
|
|
|
{ |
36
|
|
|
$this->success = $data['Success'] ?? false; |
37
|
|
|
|
38
|
|
|
if (isset($data['Message'])) { |
39
|
|
|
$this->message = $data['Message']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (isset($data['InnerResult'])) { |
43
|
|
|
$this->inner_result = $data['InnerResult']; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (isset($data['Model'])) { |
47
|
|
|
$this->getModel()->fillObjectFromArray($data['Model']); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
|
|
public function getModel(): ModelInterface |
55
|
|
|
{ |
56
|
|
|
if ($this->model === null) { |
57
|
|
|
$this->model = $this->createModel(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->model; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return ModelInterface |
65
|
|
|
*/ |
66
|
|
|
abstract protected function createModel(): ModelInterface; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
|
|
public function isSuccess(): bool |
72
|
|
|
{ |
73
|
|
|
return $this->success; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritDoc} |
78
|
|
|
*/ |
79
|
|
|
public function getMessage(): ?string |
80
|
|
|
{ |
81
|
|
|
return $this->message; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
*/ |
87
|
|
|
public function getInnerResult() |
88
|
|
|
{ |
89
|
|
|
return $this->inner_result; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritDoc} |
94
|
|
|
*/ |
95
|
|
|
public function toArray(): array |
96
|
|
|
{ |
97
|
|
|
return [ |
98
|
|
|
'Model' => $this->getModel()->toArray(), |
99
|
|
|
'Success' => $this->isSuccess(), |
100
|
|
|
'Message' => $this->getMessage(), |
101
|
|
|
'InnerResult' => $this->getInnerResult(), |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|