1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHP version 5.4 and 8 |
5
|
|
|
* |
6
|
|
|
* @category Http |
7
|
|
|
* @package Payever\Core |
8
|
|
|
* @author payever GmbH <[email protected]> |
9
|
|
|
* @copyright 2017-2021 payever GmbH |
10
|
|
|
* @license MIT <https://opensource.org/licenses/MIT> |
11
|
|
|
* @link https://docs.payever.org/shopsystems/api/getting-started |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Payever\ExternalIntegration\Core\Http; |
15
|
|
|
|
16
|
|
|
use Payever\ExternalIntegration\Core\Base\MessageEntity; |
17
|
|
|
use Payever\ExternalIntegration\Core\Http\MessageEntity\CallEntity; |
18
|
|
|
use Payever\ExternalIntegration\Core\Http\MessageEntity\ResultEntity; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This class represents ResponseInterface Entity |
22
|
|
|
* |
23
|
|
|
* @method CallEntity getCall() |
24
|
|
|
* @method string getError() |
25
|
|
|
* @method string getErrorDescription() |
26
|
|
|
* @method ResultEntity getResult() |
27
|
|
|
* |
28
|
|
|
* @SuppressWarnings(PHPMD.NumberOfChildren) |
29
|
|
|
*/ |
30
|
|
|
class ResponseEntity extends MessageEntity |
31
|
|
|
{ |
32
|
|
|
/** @var CallEntity $call */ |
33
|
|
|
protected $call; |
34
|
|
|
|
35
|
|
|
/** @var string $error */ |
36
|
|
|
protected $error; |
37
|
|
|
|
38
|
|
|
/** @var string $errorDescription */ |
39
|
|
|
protected $errorDescription; |
40
|
|
|
|
41
|
|
|
/** @var ResultEntity|array $result */ |
42
|
|
|
protected $result; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns if Entity is successful |
46
|
|
|
* |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
public function isSuccessful() |
50
|
|
|
{ |
51
|
|
|
return empty($this->error); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns if Entity is failed |
56
|
|
|
* |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function isFailed() |
60
|
|
|
{ |
61
|
|
|
return !$this->isSuccessful(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function isValid() |
68
|
|
|
{ |
69
|
|
|
return parent::isValid() && |
70
|
|
|
(!$this->call || ($this->call instanceof CallEntity && $this->call->isValid())) && |
71
|
|
|
( |
72
|
|
|
!$this->result || ($this->result instanceof ResultEntity && $this->result->isValid()) |
73
|
|
|
|| is_array($this->result) |
74
|
|
|
) |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Sets Call Entity |
80
|
|
|
* |
81
|
|
|
* @param array $call |
82
|
|
|
*/ |
83
|
|
|
public function setCall($call) |
84
|
|
|
{ |
85
|
|
|
$this->call = new CallEntity($call); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Sets Error Property |
90
|
|
|
* |
91
|
|
|
* @param array|string $error |
92
|
|
|
*/ |
93
|
|
|
public function setError($error) |
94
|
|
|
{ |
95
|
|
|
if (is_array($error)) { |
96
|
|
|
$error = json_encode($error); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$this->error = $error; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Sets ErrorDescription Property |
104
|
|
|
* |
105
|
|
|
* @param array|string $errorDescription |
106
|
|
|
*/ |
107
|
|
|
public function setErrorDescription($errorDescription) |
108
|
|
|
{ |
109
|
|
|
if (is_array($errorDescription)) { |
110
|
|
|
$errorDescription = json_encode($errorDescription); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$this->errorDescription = $errorDescription; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Sets Result Entity |
118
|
|
|
* |
119
|
|
|
* @param array $result |
120
|
|
|
*/ |
121
|
|
|
public function setResult($result) |
122
|
|
|
{ |
123
|
|
|
$this->result = new ResultEntity($result); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|