-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathActionPayload.php
More file actions
66 lines (56 loc) · 1.23 KB
/
ActionPayload.php
File metadata and controls
66 lines (56 loc) · 1.23 KB
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
<?php
declare(strict_types=1);
namespace MatchBot\Application\Actions;
use JetBrains\PhpStorm\Pure;
use JsonSerializable;
class ActionPayload implements JsonSerializable
{
/**
* @param array<mixed>|object|null $data
*/
#[Pure]
public function __construct(
private int $statusCode = 200,
private array | object | null $data = null,
private ?ActionError $error = null
) {
}
/**
* @return int
*/
#[Pure]
public function getStatusCode(): int
{
return $this->statusCode;
}
/**
* @return array<array-key,mixed>|null|object
*/
#[Pure]
public function getData(): object | array | null
{
return $this->data;
}
/**
* @return ActionError|null
*/
#[Pure]
public function getError(): ?ActionError
{
return $this->error;
}
/**
* @return object | array<mixed> | null
*/
#[\Override]
public function jsonSerialize(): object | array | null
{
$payload = null;
if ($this->data !== null) {
$payload = $this->data;
} elseif ($this->error !== null) {
$payload = ['error' => $this->error];
}
return $payload;
}
}