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 Spiral\Migrations; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Migration meta information specific to current environment |
16
|
|
|
*/ |
17
|
|
|
final class State |
18
|
|
|
{ |
19
|
|
|
// Migration status |
20
|
|
|
public const STATUS_UNDEFINED = -1; |
21
|
|
|
public const STATUS_PENDING = 0; |
22
|
|
|
public const STATUS_EXECUTED = 1; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $name; |
26
|
|
|
|
27
|
|
|
/** @var int */ |
28
|
|
|
private $status; |
29
|
|
|
|
30
|
|
|
/** @var \DateTimeInterface */ |
31
|
|
|
private $timeCreated; |
32
|
|
|
|
33
|
|
|
/** @var \DateTimeInterface|null */ |
34
|
|
|
private $timeExecuted; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $name |
38
|
|
|
* @param \DateTimeInterface $timeCreated |
39
|
|
|
* @param int $status |
40
|
|
|
* @param \DateTimeInterface $timeExecuted |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
string $name, |
44
|
|
|
\DateTimeInterface $timeCreated, |
45
|
|
|
int $status = self::STATUS_UNDEFINED, |
46
|
|
|
\DateTimeInterface $timeExecuted = null |
47
|
|
|
) { |
48
|
|
|
$this->name = $name; |
49
|
|
|
$this->status = $status; |
50
|
|
|
$this->timeCreated = $timeCreated; |
51
|
|
|
$this->timeExecuted = $timeExecuted; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getName(): string |
58
|
|
|
{ |
59
|
|
|
return $this->name; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Migration status. |
64
|
|
|
* |
65
|
|
|
* @return int |
66
|
|
|
*/ |
67
|
|
|
public function getStatus(): int |
68
|
|
|
{ |
69
|
|
|
return $this->status; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get migration creation time. |
74
|
|
|
* |
75
|
|
|
* @return \DateTimeInterface |
76
|
|
|
*/ |
77
|
|
|
public function getTimeCreated(): \DateTimeInterface |
78
|
|
|
{ |
79
|
|
|
return $this->timeCreated; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get migration execution time if any. |
84
|
|
|
* |
85
|
|
|
* @return \DateTimeInterface|null |
86
|
|
|
*/ |
87
|
|
|
public function getTimeExecuted(): ?\DateTimeInterface |
88
|
|
|
{ |
89
|
|
|
return $this->timeExecuted; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param int $status |
94
|
|
|
* @param \DateTimeInterface|null $timeExecuted |
95
|
|
|
* |
96
|
|
|
* @return State |
97
|
|
|
*/ |
98
|
|
|
public function withStatus(int $status, \DateTimeInterface $timeExecuted = null): State |
99
|
|
|
{ |
100
|
|
|
$state = clone $this; |
101
|
|
|
$state->status = $status; |
102
|
|
|
$state->timeExecuted = $timeExecuted; |
103
|
|
|
|
104
|
|
|
return $state; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|