1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
8
|
|
|
use Doctrine\Migrations\Configuration\Configuration; |
9
|
|
|
use Doctrine\Migrations\Finder\RecursiveRegexFinder; |
10
|
|
|
use Doctrine\Migrations\Provider\LazySchemaDiffProvider; |
11
|
|
|
use Doctrine\Migrations\Provider\SchemaDiffProvider; |
12
|
|
|
use Doctrine\Migrations\Provider\SchemaDiffProviderInterface; |
13
|
|
|
use Doctrine\Migrations\Tools\Console\Helper\MigrationStatusInfosHelper; |
14
|
|
|
use Symfony\Component\Stopwatch\Stopwatch as SymfonyStopwatch; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @internal |
18
|
|
|
*/ |
19
|
|
|
class DependencyFactory |
20
|
|
|
{ |
21
|
|
|
/** @var Configuration */ |
22
|
|
|
private $configuration; |
23
|
|
|
|
24
|
|
|
/** @var object[] */ |
25
|
|
|
private $dependencies = []; |
26
|
|
|
|
27
|
199 |
|
public function __construct(Configuration $configuration) |
28
|
|
|
{ |
29
|
199 |
|
$this->configuration = $configuration; |
30
|
199 |
|
} |
31
|
|
|
|
32
|
54 |
|
public function getEventDispatcher() : EventDispatcher |
33
|
|
|
{ |
34
|
|
|
return $this->getDependency(EventDispatcher::class, function () : EventDispatcher { |
35
|
54 |
|
return new EventDispatcher( |
36
|
54 |
|
$this->configuration, |
37
|
54 |
|
$this->getConnection()->getEventManager() |
38
|
|
|
); |
39
|
54 |
|
}); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function getSchemaDumper() : SchemaDumper |
43
|
|
|
{ |
44
|
|
|
return $this->getDependency(SchemaDumper::class, function () : SchemaDumper { |
45
|
1 |
|
return new SchemaDumper( |
46
|
1 |
|
$this->getConnection()->getDatabasePlatform(), |
47
|
1 |
|
$this->getConnection()->getSchemaManager(), |
48
|
1 |
|
$this->getMigrationGenerator(), |
49
|
1 |
|
$this->getMigrationSqlGenerator() |
50
|
|
|
); |
51
|
1 |
|
}); |
52
|
|
|
} |
53
|
|
|
|
54
|
143 |
|
public function getSchemaDiffProvider() : SchemaDiffProviderInterface |
55
|
|
|
{ |
56
|
|
|
return $this->getDependency(SchemaDiffProviderInterface::class, function () : LazySchemaDiffProvider { |
57
|
143 |
|
return LazySchemaDiffProvider::fromDefaultProxyFactoryConfiguration( |
58
|
143 |
|
new SchemaDiffProvider( |
59
|
143 |
|
$this->getConnection()->getSchemaManager(), |
60
|
143 |
|
$this->getConnection()->getDatabasePlatform() |
61
|
|
|
) |
62
|
|
|
); |
63
|
143 |
|
}); |
64
|
|
|
} |
65
|
|
|
|
66
|
6 |
|
public function getMigrationFileBuilder() : MigrationFileBuilder |
67
|
|
|
{ |
68
|
|
|
return $this->getDependency(MigrationFileBuilder::class, function () : MigrationFileBuilder { |
69
|
6 |
|
return new MigrationFileBuilder( |
70
|
6 |
|
$this->getConnection()->getDatabasePlatform(), |
71
|
6 |
|
$this->configuration->getMigrationsTableName(), |
72
|
6 |
|
$this->configuration->getQuotedMigrationsColumnName(), |
73
|
6 |
|
$this->configuration->getQuotedMigrationsExecutedAtColumnName() |
74
|
|
|
); |
75
|
6 |
|
}); |
76
|
|
|
} |
77
|
|
|
|
78
|
143 |
|
public function getParameterFormatter() : ParameterFormatterInterface |
79
|
|
|
{ |
80
|
|
|
return $this->getDependency(ParameterFormatter::class, function () : ParameterFormatter { |
81
|
143 |
|
return new ParameterFormatter($this->getConnection()); |
82
|
143 |
|
}); |
83
|
|
|
} |
84
|
|
|
|
85
|
143 |
|
public function getMigrationRepository() : MigrationRepository |
86
|
|
|
{ |
87
|
|
|
return $this->getDependency(MigrationRepository::class, function () : MigrationRepository { |
88
|
143 |
|
return new MigrationRepository( |
89
|
143 |
|
$this->configuration, |
90
|
143 |
|
$this->getConnection(), |
91
|
143 |
|
$this->configuration->getMigrationsFinder(), |
92
|
143 |
|
new VersionFactory($this->configuration, $this->getVersionExecutor()) |
93
|
|
|
); |
94
|
143 |
|
}); |
95
|
|
|
} |
96
|
|
|
|
97
|
73 |
|
public function getMigrationTableManipulator() : MigrationTableManipulator |
98
|
|
|
{ |
99
|
|
|
return $this->getDependency(MigrationTableManipulator::class, function () : MigrationTableManipulator { |
100
|
73 |
|
return new MigrationTableManipulator( |
101
|
73 |
|
$this->configuration, |
102
|
73 |
|
$this->getConnection()->getSchemaManager(), |
103
|
73 |
|
$this->getMigrationTable(), |
104
|
73 |
|
$this->getMigrationTableStatus(), |
105
|
73 |
|
$this->getMigrationTableUpdater() |
106
|
|
|
); |
107
|
73 |
|
}); |
108
|
|
|
} |
109
|
|
|
|
110
|
80 |
|
public function getMigrationTable() : MigrationTable |
111
|
|
|
{ |
112
|
|
|
return $this->getDependency(MigrationTable::class, function () : MigrationTable { |
113
|
80 |
|
return new MigrationTable( |
114
|
80 |
|
$this->getConnection()->getSchemaManager(), |
115
|
80 |
|
$this->configuration->getMigrationsTableName(), |
116
|
80 |
|
$this->configuration->getMigrationsColumnName(), |
117
|
80 |
|
$this->configuration->getMigrationsColumnLength(), |
118
|
80 |
|
$this->configuration->getMigrationsExecutedAtColumnName() |
119
|
|
|
); |
120
|
80 |
|
}); |
121
|
|
|
} |
122
|
|
|
|
123
|
73 |
|
public function getMigrationTableStatus() : MigrationTableStatus |
124
|
|
|
{ |
125
|
|
|
return $this->getDependency(MigrationTableStatus::class, function () : MigrationTableStatus { |
126
|
73 |
|
return new MigrationTableStatus( |
127
|
73 |
|
$this->getConnection()->getSchemaManager(), |
128
|
73 |
|
$this->getMigrationTable() |
129
|
|
|
); |
130
|
73 |
|
}); |
131
|
|
|
} |
132
|
|
|
|
133
|
73 |
|
public function getMigrationTableUpdater() : MigrationTableUpdater |
134
|
|
|
{ |
135
|
|
|
return $this->getDependency(MigrationTableUpdater::class, function () : MigrationTableUpdater { |
136
|
73 |
|
return new MigrationTableUpdater( |
137
|
73 |
|
$this->getConnection(), |
138
|
73 |
|
$this->getConnection()->getSchemaManager(), |
139
|
73 |
|
$this->getMigrationTable(), |
140
|
73 |
|
$this->getConnection()->getDatabasePlatform() |
141
|
|
|
); |
142
|
73 |
|
}); |
143
|
|
|
} |
144
|
|
|
|
145
|
143 |
|
public function getVersionExecutor() : VersionExecutor |
146
|
|
|
{ |
147
|
|
|
return $this->getDependency(VersionExecutor::class, function () : VersionExecutor { |
148
|
143 |
|
return new VersionExecutor( |
149
|
143 |
|
$this->configuration, |
150
|
143 |
|
$this->getConnection(), |
151
|
143 |
|
$this->getSchemaDiffProvider(), |
152
|
143 |
|
$this->getOutputWriter(), |
153
|
143 |
|
$this->getParameterFormatter(), |
154
|
143 |
|
$this->getStopwatch() |
155
|
|
|
); |
156
|
143 |
|
}); |
157
|
|
|
} |
158
|
|
|
|
159
|
6 |
|
public function getQueryWriter() : FileQueryWriter |
160
|
|
|
{ |
161
|
|
|
return $this->getDependency(FileQueryWriter::class, function () : FileQueryWriter { |
162
|
6 |
|
return new FileQueryWriter( |
163
|
6 |
|
$this->getOutputWriter(), |
164
|
6 |
|
$this->getMigrationFileBuilder() |
165
|
|
|
); |
166
|
6 |
|
}); |
167
|
|
|
} |
168
|
|
|
|
169
|
164 |
|
public function getOutputWriter() : OutputWriter |
170
|
|
|
{ |
171
|
|
|
return $this->getDependency(OutputWriter::class, function () : OutputWriter { |
172
|
164 |
|
return new OutputWriter(); |
173
|
164 |
|
}); |
174
|
|
|
} |
175
|
|
|
|
176
|
8 |
|
public function getVersionAliasResolver() : VersionAliasResolver |
177
|
|
|
{ |
178
|
|
|
return $this->getDependency(VersionAliasResolver::class, function () : VersionAliasResolver { |
179
|
8 |
|
return new VersionAliasResolver( |
180
|
8 |
|
$this->getMigrationRepository() |
181
|
|
|
); |
182
|
8 |
|
}); |
183
|
|
|
} |
184
|
|
|
|
185
|
33 |
|
public function getMigrationPlanCalculator() : MigrationPlanCalculator |
186
|
|
|
{ |
187
|
|
|
return $this->getDependency(MigrationPlanCalculator::class, function () : MigrationPlanCalculator { |
188
|
33 |
|
return new MigrationPlanCalculator($this->getMigrationRepository()); |
189
|
33 |
|
}); |
190
|
|
|
} |
191
|
|
|
|
192
|
157 |
|
public function getRecursiveRegexFinder() : RecursiveRegexFinder |
193
|
|
|
{ |
194
|
|
|
return $this->getDependency(RecursiveRegexFinder::class, function () : RecursiveRegexFinder { |
195
|
157 |
|
return new RecursiveRegexFinder(); |
196
|
157 |
|
}); |
197
|
|
|
} |
198
|
|
|
|
199
|
8 |
|
public function getMigrationGenerator() : MigrationGenerator |
200
|
|
|
{ |
201
|
|
|
return $this->getDependency(MigrationGenerator::class, function () : MigrationGenerator { |
202
|
8 |
|
return new MigrationGenerator($this->configuration); |
203
|
8 |
|
}); |
204
|
|
|
} |
205
|
|
|
|
206
|
6 |
|
public function getMigrationSqlGenerator() : MigrationSqlGenerator |
207
|
|
|
{ |
208
|
|
|
return $this->getDependency(MigrationSqlGenerator::class, function () : MigrationSqlGenerator { |
209
|
6 |
|
return new MigrationSqlGenerator( |
210
|
6 |
|
$this->configuration, |
211
|
6 |
|
$this->getConnection()->getDatabasePlatform() |
212
|
|
|
); |
213
|
6 |
|
}); |
214
|
|
|
} |
215
|
|
|
|
216
|
8 |
|
public function getMigrationStatusInfosHelper() : MigrationStatusInfosHelper |
217
|
|
|
{ |
218
|
|
|
return $this->getDependency(MigrationStatusInfosHelper::class, function () : MigrationStatusInfosHelper { |
219
|
8 |
|
return new MigrationStatusInfosHelper( |
220
|
8 |
|
$this->configuration, |
221
|
8 |
|
$this->getMigrationRepository() |
222
|
|
|
); |
223
|
8 |
|
}); |
224
|
|
|
} |
225
|
|
|
|
226
|
1 |
|
public function getMigrator() : Migrator |
227
|
|
|
{ |
228
|
|
|
return $this->getDependency(Migrator::class, function () : Migrator { |
229
|
1 |
|
return new Migrator( |
230
|
1 |
|
$this->configuration, |
231
|
1 |
|
$this->getMigrationRepository(), |
232
|
1 |
|
$this->getOutputWriter(), |
233
|
1 |
|
$this->getStopwatch() |
234
|
|
|
); |
235
|
1 |
|
}); |
236
|
|
|
} |
237
|
|
|
|
238
|
143 |
|
public function getStopwatch() : Stopwatch |
239
|
|
|
{ |
240
|
|
|
return $this->getDependency(Stopwatch::class, function () : Stopwatch { |
241
|
143 |
|
$symfonyStopwatch = new SymfonyStopwatch(true); |
242
|
|
|
|
243
|
143 |
|
return new Stopwatch($symfonyStopwatch); |
244
|
143 |
|
}); |
245
|
|
|
} |
246
|
|
|
|
247
|
1 |
|
public function getRollup() : Rollup |
248
|
|
|
{ |
249
|
|
|
return $this->getDependency(Rollup::class, function () : Rollup { |
250
|
1 |
|
return new Rollup( |
251
|
1 |
|
$this->configuration, |
252
|
1 |
|
$this->getConnection(), |
253
|
1 |
|
$this->getMigrationRepository() |
254
|
|
|
); |
255
|
1 |
|
}); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return mixed |
260
|
|
|
*/ |
261
|
199 |
|
private function getDependency(string $className, callable $callback) |
262
|
|
|
{ |
263
|
199 |
|
if (! isset($this->dependencies[$className])) { |
264
|
199 |
|
$this->dependencies[$className] = $callback(); |
265
|
|
|
} |
266
|
|
|
|
267
|
199 |
|
return $this->dependencies[$className]; |
268
|
|
|
} |
269
|
|
|
|
270
|
172 |
|
private function getConnection() : Connection |
271
|
|
|
{ |
272
|
172 |
|
return $this->configuration->getConnection(); |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|