-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSharpApiJob.php
More file actions
91 lines (80 loc) · 1.8 KB
/
SharpApiJob.php
File metadata and controls
91 lines (80 loc) · 1.8 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
namespace SharpAPI\SharpApiService\Dto;
use SharpAPI\SharpApiService\Enums\SharpApiJobStatusEnum;
use SharpAPI\SharpApiService\Enums\SharpApiJobTypeEnum;
use stdClass;
class SharpApiJob
{
public function __construct(
public string $id,
public string $type,
public string $status,
public ?stdClass $result
)
{
}
public function toArray(): array
{
return [
'id' => $this->id,
'type' => $this->type,
'status' => $this->status,
'result' => $this->result,
];
}
/**
* Returns SharpAPI job ID (UUID format)
*
* @api
*/
public function getId(): string
{
return $this->id;
}
/**
* Returns one of the job types available in SharpApiJobTypeEnum
*
* @api
*/
public function getType(): SharpApiJobTypeEnum
{
return SharpApiJobTypeEnum::from($this->type);
}
/**
* Returns one of the job statuses available in SharpApiJobStatusEnum
*
* @api
*/
public function getStatus(): SharpApiJobStatusEnum
{
return SharpApiJobStatusEnum::from($this->status);
}
/**
* Returns job result as a prettied JSON
*
* @api
*/
public function getResultJson(): string|bool|null
{
return $this->result ? json_encode($this->result, JSON_PRETTY_PRINT) : null;
}
/**
* Returns job result contents as PHP associative array
*
* @api
*/
public function getResultArray(): ?array
{
return (array) $this->result;
}
/**
* Returns job result contents as PHP stdClass object
*
* @api
*/
public function getResultObject(): ?stdClass
{
return $this->result;
}
}