|
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
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @internal |
|
17
|
|
|
*/ |
|
18
|
|
|
class DependencyFactory |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var Configuration */ |
|
21
|
|
|
private $configuration; |
|
22
|
|
|
|
|
23
|
|
|
/** @var object[] */ |
|
24
|
|
|
private $dependencies = []; |
|
25
|
|
|
|
|
26
|
182 |
|
public function __construct(Configuration $configuration) |
|
27
|
|
|
{ |
|
28
|
182 |
|
$this->configuration = $configuration; |
|
29
|
182 |
|
} |
|
30
|
|
|
|
|
31
|
52 |
|
public function getEventDispatcher() : EventDispatcher |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->getDependency(EventDispatcher::class, function () { |
|
34
|
52 |
|
return new EventDispatcher( |
|
35
|
52 |
|
$this->configuration, |
|
36
|
52 |
|
$this->getConnection()->getEventManager() |
|
37
|
|
|
); |
|
38
|
52 |
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
130 |
|
public function getSchemaDiffProvider() : SchemaDiffProviderInterface |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->getDependency(SchemaDiffProviderInterface::class, function () { |
|
44
|
130 |
|
return LazySchemaDiffProvider::fromDefaultProxyFactoryConfiguration( |
|
45
|
130 |
|
new SchemaDiffProvider( |
|
46
|
130 |
|
$this->getConnection()->getSchemaManager(), |
|
47
|
130 |
|
$this->getConnection()->getDatabasePlatform() |
|
48
|
|
|
) |
|
49
|
|
|
); |
|
50
|
130 |
|
}); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
public function getMigrationFileBuilder() : MigrationFileBuilder |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getDependency(MigrationFileBuilder::class, function () { |
|
56
|
6 |
|
return new MigrationFileBuilder( |
|
57
|
6 |
|
$this->configuration->getMigrationsTableName(), |
|
58
|
6 |
|
$this->configuration->getQuotedMigrationsColumnName() |
|
59
|
|
|
); |
|
60
|
6 |
|
}); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
130 |
|
public function getParameterFormatter() : ParameterFormatterInterface |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->getDependency(ParameterFormatter::class, function () { |
|
66
|
130 |
|
return new ParameterFormatter($this->getConnection()); |
|
67
|
130 |
|
}); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
130 |
|
public function getMigrationRepository() : MigrationRepository |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->getDependency(MigrationRepository::class, function () { |
|
73
|
130 |
|
return new MigrationRepository( |
|
74
|
130 |
|
$this->configuration, |
|
75
|
130 |
|
$this->getConnection(), |
|
76
|
130 |
|
$this->configuration->getMigrationsFinder(), |
|
77
|
130 |
|
new VersionFactory($this->configuration, $this->getVersionExecutor()) |
|
78
|
|
|
); |
|
79
|
130 |
|
}); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
70 |
|
public function getMigrationTableCreator() : MigrationTableCreator |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->getDependency(MigrationTableCreator::class, function () { |
|
85
|
70 |
|
return new MigrationTableCreator( |
|
86
|
70 |
|
$this->configuration, |
|
87
|
70 |
|
$this->getConnection()->getSchemaManager() |
|
88
|
|
|
); |
|
89
|
70 |
|
}); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
130 |
|
public function getVersionExecutor() : VersionExecutor |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->getDependency(VersionExecutor::class, function () { |
|
95
|
130 |
|
return new VersionExecutor( |
|
96
|
130 |
|
$this->configuration, |
|
97
|
130 |
|
$this->getConnection(), |
|
98
|
130 |
|
$this->getSchemaDiffProvider(), |
|
99
|
130 |
|
$this->getOutputWriter(), |
|
100
|
130 |
|
$this->getParameterFormatter() |
|
101
|
|
|
); |
|
102
|
130 |
|
}); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
6 |
|
public function getQueryWriter() : FileQueryWriter |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->getDependency(FileQueryWriter::class, function () { |
|
108
|
6 |
|
return new FileQueryWriter( |
|
109
|
6 |
|
$this->getOutputWriter(), |
|
110
|
6 |
|
$this->getMigrationFileBuilder() |
|
111
|
|
|
); |
|
112
|
6 |
|
}); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
150 |
|
public function getOutputWriter() : OutputWriter |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->getDependency(OutputWriter::class, function () { |
|
118
|
150 |
|
return new OutputWriter(); |
|
119
|
150 |
|
}); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
8 |
|
public function getVersionAliasResolver() : VersionAliasResolver |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->getDependency(VersionAliasResolver::class, function () { |
|
125
|
8 |
|
return new VersionAliasResolver( |
|
126
|
8 |
|
$this->getMigrationRepository() |
|
127
|
|
|
); |
|
128
|
8 |
|
}); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
33 |
|
public function getMigrationPlanCalculator() : MigrationPlanCalculator |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->getDependency(MigrationPlanCalculator::class, function () { |
|
134
|
33 |
|
return new MigrationPlanCalculator($this->getMigrationRepository()); |
|
135
|
33 |
|
}); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
144 |
|
public function getRecursiveRegexFinder() : RecursiveRegexFinder |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->getDependency(RecursiveRegexFinder::class, function () { |
|
141
|
144 |
|
return new RecursiveRegexFinder(); |
|
142
|
144 |
|
}); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
7 |
|
public function getMigrationGenerator() : MigrationGenerator |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->getDependency(MigrationGenerator::class, function () { |
|
148
|
7 |
|
return new MigrationGenerator($this->configuration); |
|
149
|
7 |
|
}); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
5 |
|
public function getMigrationSqlGenerator() : MigrationSqlGenerator |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->getDependency(MigrationSqlGenerator::class, function () { |
|
155
|
5 |
|
return new MigrationSqlGenerator( |
|
156
|
5 |
|
$this->configuration, |
|
157
|
5 |
|
$this->getConnection()->getDatabasePlatform() |
|
158
|
|
|
); |
|
159
|
5 |
|
}); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
8 |
|
public function getMigrationStatusInfosHelper() : MigrationStatusInfosHelper |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->getDependency(MigrationStatusInfosHelper::class, function () { |
|
165
|
8 |
|
return new MigrationStatusInfosHelper( |
|
166
|
8 |
|
$this->configuration, |
|
167
|
8 |
|
$this->getMigrationRepository() |
|
168
|
|
|
); |
|
169
|
8 |
|
}); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
1 |
|
public function getMigrator() : Migrator |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->getDependency(Migrator::class, function () { |
|
175
|
1 |
|
return new Migrator( |
|
176
|
1 |
|
$this->configuration, |
|
177
|
1 |
|
$this->getMigrationRepository(), |
|
178
|
1 |
|
$this->getOutputWriter() |
|
179
|
|
|
); |
|
180
|
1 |
|
}); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @return mixed |
|
185
|
|
|
*/ |
|
186
|
182 |
|
private function getDependency(string $className, callable $callback) |
|
187
|
|
|
{ |
|
188
|
182 |
|
if (! isset($this->dependencies[$className])) { |
|
189
|
182 |
|
$this->dependencies[$className] = $callback(); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
182 |
|
return $this->dependencies[$className]; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
154 |
|
private function getConnection() : Connection |
|
196
|
|
|
{ |
|
197
|
154 |
|
return $this->configuration->getConnection(); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|