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