|
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\ResponseInterface; |
|
17
|
|
|
use Payever\ExternalIntegration\Core\Helper\StringHelper; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* This class represents ResponseInterface |
|
21
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
22
|
|
|
*/ |
|
23
|
|
|
class Response implements ResponseInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var RequestEntity $requestEntity */ |
|
26
|
|
|
protected $requestEntity; |
|
27
|
|
|
|
|
28
|
|
|
/** @var ResponseEntity $responseEntity */ |
|
29
|
|
|
protected $responseEntity; |
|
30
|
|
|
|
|
31
|
|
|
/** @var array|string|object $data */ |
|
32
|
|
|
protected $data; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* ResponseInterface constructor |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->responseEntity = new ResponseEntity(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function load($data) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->data = $data; |
|
48
|
|
|
|
|
49
|
|
|
$this |
|
50
|
|
|
->getResponseEntity() |
|
51
|
|
|
->load($data ? StringHelper::jsonDecode($this->data) : []) |
|
52
|
|
|
; |
|
53
|
|
|
|
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setRequestEntity(RequestEntity $requestEntity) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->requestEntity = $requestEntity; |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setResponseEntity(ResponseEntity $responseEntity) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->responseEntity = $responseEntity; |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getRequestEntity() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->requestEntity; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getResponseEntity() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->responseEntity; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns if ResponseInterface is successful |
|
95
|
|
|
* |
|
96
|
|
|
* @return bool |
|
97
|
|
|
*/ |
|
98
|
|
|
public function isSuccessful() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getResponseEntity()->isSuccessful(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Returns if ResponseInterface is failed |
|
105
|
|
|
* |
|
106
|
|
|
* @return bool |
|
107
|
|
|
*/ |
|
108
|
|
|
public function isFailed() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->getResponseEntity()->isFailed(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Returns data from ResponseInterface |
|
115
|
|
|
* |
|
116
|
|
|
* @return string |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getData() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->data; |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|