1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/** |
5
|
|
|
* JobStatus.php |
6
|
|
|
* Copyright (c) 2020 [email protected]. |
7
|
|
|
* |
8
|
|
|
* This file is part of the Firefly III bunq importer |
9
|
|
|
* (https://github.com/firefly-iii/bunq-importer). |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace App\Services\Sync\JobStatus; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class JobStatus. |
29
|
|
|
*/ |
30
|
|
|
class JobStatus |
31
|
|
|
{ |
32
|
|
|
/** @var string */ |
33
|
|
|
public const JOB_WAITING = 'waiting_to_start'; |
34
|
|
|
/** @var string */ |
35
|
|
|
public const JOB_RUNNING = 'job_running'; |
36
|
|
|
/** @var string */ |
37
|
|
|
public const JOB_ERRORED = 'job_errored'; |
38
|
|
|
/** @var string */ |
39
|
|
|
public const JOB_DONE = 'job_done'; |
40
|
|
|
/** @var array */ |
41
|
|
|
public $errors; |
42
|
|
|
/** @var array */ |
43
|
|
|
public $messages; |
44
|
|
|
/** @var string */ |
45
|
|
|
public $status; |
46
|
|
|
/** @var array */ |
47
|
|
|
public $warnings; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* ImportJobStatus constructor. |
51
|
|
|
*/ |
52
|
|
|
public function __construct() |
53
|
|
|
{ |
54
|
|
|
$this->status = self::JOB_WAITING; |
55
|
|
|
$this->errors = []; |
56
|
|
|
$this->warnings = []; |
57
|
|
|
$this->messages = []; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param array $array |
62
|
|
|
* |
63
|
|
|
* @return static |
64
|
|
|
*/ |
65
|
|
|
public static function fromArray(array $array): self |
66
|
|
|
{ |
67
|
|
|
$config = new self; |
68
|
|
|
$config->status = $array['status']; |
69
|
|
|
$config->errors = $array['errors'] ?? []; |
70
|
|
|
$config->warnings = $array['warnings'] ?? []; |
71
|
|
|
$config->messages = $array['messages'] ?? []; |
72
|
|
|
|
73
|
|
|
return $config; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function toArray(): array |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
'status' => $this->status, |
83
|
|
|
'errors' => $this->errors, |
84
|
|
|
'warnings' => $this->warnings, |
85
|
|
|
'messages' => $this->messages, |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|