|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Configuration; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Migrations\Configuration\Exception\FrozenConfiguration; |
|
8
|
|
|
use Doctrine\Migrations\Configuration\Exception\UnknownConfigurationValue; |
|
9
|
|
|
use Doctrine\Migrations\Exception\MigrationException; |
|
10
|
|
|
use Doctrine\Migrations\Metadata\Storage\MetadataStorageConfiguration; |
|
11
|
|
|
use function strcasecmp; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The Configuration class is responsible for defining migration configuration information. |
|
15
|
|
|
*/ |
|
16
|
|
|
final class Configuration |
|
17
|
|
|
{ |
|
18
|
|
|
public const VERSIONS_ORGANIZATION_BY_YEAR = 'year'; |
|
19
|
|
|
public const VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH = 'year_and_month'; |
|
20
|
|
|
|
|
21
|
|
|
/** @var array<string, string> */ |
|
22
|
|
|
private $migrationsDirectories = []; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string[] */ |
|
25
|
|
|
private $migrationClasses = []; |
|
26
|
|
|
|
|
27
|
|
|
/** @var bool */ |
|
28
|
|
|
private $migrationsAreOrganizedByYear = false; |
|
29
|
|
|
|
|
30
|
|
|
/** @var bool */ |
|
31
|
|
|
private $migrationsAreOrganizedByYearAndMonth = false; |
|
32
|
|
|
|
|
33
|
|
|
/** @var string|null */ |
|
34
|
|
|
private $customTemplate; |
|
35
|
|
|
|
|
36
|
|
|
/** @var bool */ |
|
37
|
|
|
private $isDryRun = false; |
|
38
|
|
|
|
|
39
|
|
|
/** @var bool */ |
|
40
|
|
|
private $allOrNothing = false; |
|
41
|
|
|
|
|
42
|
|
|
/** @var bool */ |
|
43
|
|
|
private $checkDbPlatform = true; |
|
44
|
|
|
|
|
45
|
|
|
/** @var MetadataStorageConfiguration */ |
|
46
|
|
|
private $metadataStorageConfiguration; |
|
47
|
|
|
|
|
48
|
|
|
/** @var bool */ |
|
49
|
|
|
private $frozen = false; |
|
50
|
|
|
|
|
51
|
70 |
|
public function freeze() : void |
|
52
|
|
|
{ |
|
53
|
70 |
|
$this->frozen = true; |
|
54
|
70 |
|
} |
|
55
|
|
|
|
|
56
|
140 |
|
private function assertNotFrozen() : void |
|
57
|
|
|
{ |
|
58
|
140 |
|
if ($this->frozen) { |
|
59
|
1 |
|
throw FrozenConfiguration::new(); |
|
60
|
|
|
} |
|
61
|
140 |
|
} |
|
62
|
|
|
|
|
63
|
97 |
|
public function setMetadataStorageConfiguration(MetadataStorageConfiguration $metadataStorageConfiguration) : void |
|
64
|
|
|
{ |
|
65
|
97 |
|
$this->assertNotFrozen(); |
|
66
|
97 |
|
$this->metadataStorageConfiguration = $metadataStorageConfiguration; |
|
67
|
97 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return string[] |
|
71
|
|
|
*/ |
|
72
|
44 |
|
public function getMigrationClasses() : array |
|
73
|
|
|
{ |
|
74
|
44 |
|
return $this->migrationClasses; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
10 |
|
public function addMigrationClass(string $className) : void |
|
78
|
|
|
{ |
|
79
|
10 |
|
$this->assertNotFrozen(); |
|
80
|
10 |
|
$this->migrationClasses[] = $className; |
|
81
|
10 |
|
} |
|
82
|
|
|
|
|
83
|
66 |
|
public function getMetadataStorageConfiguration() : ?MetadataStorageConfiguration |
|
84
|
|
|
{ |
|
85
|
66 |
|
return $this->metadataStorageConfiguration; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
91 |
|
public function addMigrationsDirectory(string $namespace, string $path) : void |
|
89
|
|
|
{ |
|
90
|
91 |
|
$this->assertNotFrozen(); |
|
91
|
91 |
|
$this->migrationsDirectories[$namespace] = $path; |
|
92
|
91 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return array<string,string> |
|
96
|
|
|
*/ |
|
97
|
59 |
|
public function getMigrationDirectories() : array |
|
98
|
|
|
{ |
|
99
|
59 |
|
return $this->migrationsDirectories; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
10 |
|
public function setCustomTemplate(?string $customTemplate) : void |
|
103
|
|
|
{ |
|
104
|
10 |
|
$this->assertNotFrozen(); |
|
105
|
10 |
|
$this->customTemplate = $customTemplate; |
|
106
|
10 |
|
} |
|
107
|
|
|
|
|
108
|
12 |
|
public function getCustomTemplate() : ?string |
|
109
|
|
|
{ |
|
110
|
12 |
|
return $this->customTemplate; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
58 |
|
public function areMigrationsOrganizedByYear() : bool |
|
114
|
|
|
{ |
|
115
|
58 |
|
return $this->migrationsAreOrganizedByYear; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @throws MigrationException |
|
120
|
|
|
*/ |
|
121
|
7 |
|
public function setMigrationsAreOrganizedByYear( |
|
122
|
|
|
bool $migrationsAreOrganizedByYear = true |
|
123
|
|
|
) : void { |
|
124
|
7 |
|
$this->assertNotFrozen(); |
|
125
|
7 |
|
$this->migrationsAreOrganizedByYear = $migrationsAreOrganizedByYear; |
|
126
|
7 |
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @throws MigrationException |
|
130
|
|
|
*/ |
|
131
|
7 |
|
public function setMigrationsAreOrganizedByYearAndMonth( |
|
132
|
|
|
bool $migrationsAreOrganizedByYearAndMonth = true |
|
133
|
|
|
) : void { |
|
134
|
7 |
|
$this->assertNotFrozen(); |
|
135
|
7 |
|
$this->migrationsAreOrganizedByYear = $migrationsAreOrganizedByYearAndMonth; |
|
136
|
7 |
|
$this->migrationsAreOrganizedByYearAndMonth = $migrationsAreOrganizedByYearAndMonth; |
|
137
|
7 |
|
} |
|
138
|
|
|
|
|
139
|
56 |
|
public function areMigrationsOrganizedByYearAndMonth() : bool |
|
140
|
|
|
{ |
|
141
|
56 |
|
return $this->migrationsAreOrganizedByYearAndMonth; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
1 |
|
public function setIsDryRun(bool $isDryRun) : void |
|
145
|
|
|
{ |
|
146
|
1 |
|
$this->assertNotFrozen(); |
|
147
|
1 |
|
$this->isDryRun = $isDryRun; |
|
148
|
1 |
|
} |
|
149
|
|
|
|
|
150
|
1 |
|
public function isDryRun() : bool |
|
151
|
|
|
{ |
|
152
|
1 |
|
return $this->isDryRun; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
11 |
|
public function setAllOrNothing(bool $allOrNothing) : void |
|
156
|
|
|
{ |
|
157
|
11 |
|
$this->assertNotFrozen(); |
|
158
|
10 |
|
$this->allOrNothing = $allOrNothing; |
|
159
|
10 |
|
} |
|
160
|
|
|
|
|
161
|
10 |
|
public function isAllOrNothing() : bool |
|
162
|
|
|
{ |
|
163
|
10 |
|
return $this->allOrNothing; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
11 |
|
public function setCheckDatabasePlatform(bool $checkDbPlatform) : void |
|
167
|
|
|
{ |
|
168
|
11 |
|
$this->checkDbPlatform = $checkDbPlatform; |
|
169
|
11 |
|
} |
|
170
|
|
|
|
|
171
|
3 |
|
public function isDatabasePlatformChecked() : bool |
|
172
|
|
|
{ |
|
173
|
3 |
|
return $this->checkDbPlatform; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
14 |
|
public function setMigrationOrganization(string $migrationOrganization) : void |
|
177
|
|
|
{ |
|
178
|
14 |
|
$this->assertNotFrozen(); |
|
179
|
14 |
|
if (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR) === 0) { |
|
180
|
5 |
|
$this->setMigrationsAreOrganizedByYear(); |
|
181
|
9 |
|
} elseif (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH) === 0) { |
|
182
|
5 |
|
$this->setMigrationsAreOrganizedByYearAndMonth(); |
|
183
|
|
|
} else { |
|
184
|
4 |
|
throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization); |
|
185
|
|
|
} |
|
186
|
10 |
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|