|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace W2w\Lib\Apie\Events; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Event mediator for decoding a string to an array |
|
7
|
|
|
*/ |
|
8
|
|
|
class DecodeEvent |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var object|null |
|
12
|
|
|
*/ |
|
13
|
|
|
private $resource; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $acceptHeader; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string|int|array|null|float |
|
23
|
|
|
*/ |
|
24
|
|
|
private $decodedData; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
private $hasData = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $requestBody; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
private $resourceClass; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $requestBody |
|
43
|
|
|
* @param string $acceptHeader |
|
44
|
|
|
* @param object|null $resource |
|
45
|
|
|
* @param string $resourceClass |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(string $requestBody, string $acceptHeader, ?object $resource, string $resourceClass) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->requestBody = $requestBody; |
|
50
|
|
|
$this->acceptHeader = $acceptHeader; |
|
51
|
|
|
$this->resource = $resource; |
|
52
|
|
|
$this->resourceClass = $resourceClass; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string|int|array|null|float |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getDecodedData() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->decodedData; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string|int|array|null|float $normalizedData |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setDecodedData($normalizedData): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->decodedData = $normalizedData; |
|
69
|
|
|
$this->hasData = true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* If not null, it means an existing resource is being modified. |
|
74
|
|
|
* |
|
75
|
|
|
* @return object|null |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getResource(): ?object |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->resource; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getAcceptHeader(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->acceptHeader; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getRequestBody(): string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->requestBody; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
|
|
public function hasDecodedData(): bool |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->hasData; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getResourceClass(): string |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->resourceClass; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|