|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Cycle\Migrations\Migration; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Migration meta information specific to current environment. |
|
16
|
|
|
* |
|
17
|
|
|
* @psalm-import-type StatusEnum from Status |
|
18
|
|
|
* |
|
19
|
|
|
* @internal State is an internal library class, please do not use it in your code. |
|
20
|
|
|
* @psalm-internal Cycle\Migrations |
|
21
|
|
|
*/ |
|
22
|
|
|
class State |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var non-empty-string |
|
|
|
|
|
|
26
|
|
|
*/ |
|
27
|
|
|
private $name; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var StatusEnum |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
private $status; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var \DateTimeInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $createdAt; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var \DateTimeInterface|null |
|
41
|
|
|
*/ |
|
42
|
|
|
private $executedAt; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param non-empty-string $name |
|
|
|
|
|
|
46
|
|
|
* @param \DateTimeInterface $createdAt |
|
47
|
|
|
* @param StatusEnum $status |
|
48
|
|
|
* @param \DateTimeInterface|null $executedAt |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct( |
|
51
|
|
|
string $name, |
|
52
|
|
|
\DateTimeInterface $createdAt, |
|
53
|
|
|
int $status = Status::STATUS_UNDEFINED, |
|
54
|
|
|
\DateTimeInterface $executedAt = null |
|
55
|
|
|
) { |
|
56
|
|
|
$this->name = $name; |
|
57
|
|
|
$this->status = $status; |
|
|
|
|
|
|
58
|
|
|
$this->createdAt = $createdAt; |
|
59
|
|
|
$this->executedAt = $executedAt; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getName(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->name; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Migration status. |
|
72
|
|
|
* |
|
73
|
|
|
* @return int |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getStatus(): int |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->status; |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get migration creation time. |
|
82
|
|
|
* |
|
83
|
|
|
* @return \DateTimeInterface |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getTimeCreated(): \DateTimeInterface |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->createdAt; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get migration execution time if any. |
|
92
|
|
|
* |
|
93
|
|
|
* @return \DateTimeInterface|null |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getTimeExecuted(): ?\DateTimeInterface |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->executedAt; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param StatusEnum $status |
|
102
|
|
|
* @param \DateTimeInterface|null $executedAt |
|
103
|
|
|
* @return State |
|
104
|
|
|
*/ |
|
105
|
|
|
public function withStatus(int $status, \DateTimeInterface $executedAt = null): State |
|
106
|
|
|
{ |
|
107
|
|
|
$state = clone $this; |
|
108
|
|
|
$state->status = $status; |
|
|
|
|
|
|
109
|
|
|
$state->executedAt = $executedAt; |
|
110
|
|
|
|
|
111
|
|
|
return $state; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|