1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine-fixture-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\DoctrineFixtureModule\Executor; |
7
|
|
|
|
8
|
|
|
use Doctrine\Fixture\Loader\Loader; |
9
|
|
|
use Doctrine\Fixture\Filter\Filter; |
10
|
|
|
use Doctrine\Fixture\Configuration; |
11
|
|
|
use Doctrine\Fixture\Loader\ChainLoader; |
12
|
|
|
use Doctrine\Fixture\Filter\ChainFilter; |
13
|
|
|
use Doctrine\Fixture\Executor as FixtureExecutor; |
14
|
|
|
use Nnx\DoctrineFixtureModule\FixtureInitializer\FixtureInitializerManagerInterface; |
15
|
|
|
use Nnx\DoctrineFixtureModule\FixtureInitializer\ResourceLoaderInitializer; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Executor |
19
|
|
|
* |
20
|
|
|
* @package Nnx\DoctrineFixtureModule\Executor |
21
|
|
|
*/ |
22
|
|
|
class Executor implements ExecutorInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Загрузчик фикстур |
26
|
|
|
* |
27
|
|
|
* @var Loader |
28
|
|
|
*/ |
29
|
|
|
protected $loader; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Фильтр фикстур |
33
|
|
|
* |
34
|
|
|
* @var Filter |
35
|
|
|
*/ |
36
|
|
|
protected $filter; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Конфигурация компонета отвечающего за выполнение фикстур |
40
|
|
|
* |
41
|
|
|
* @var Configuration |
42
|
|
|
*/ |
43
|
|
|
protected $configuration; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Компонент отвечающий за выполение фикстур |
47
|
|
|
* |
48
|
|
|
* @var FixtureExecutor |
49
|
|
|
*/ |
50
|
|
|
protected $fixtureExecutor; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Имя |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $name = Executor::class; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Сервис, отвечающий за создание компонента выполняющего фикстуры |
61
|
|
|
* |
62
|
|
|
* |
63
|
|
|
* @var FixtureExecutorBuilderInterface |
64
|
|
|
*/ |
65
|
|
|
protected $fixtureExecutorBuilder; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Инициалайзеры, создаваемые заново перед каждым запуском фикстур. При создание этих инициайзеров, им передаются |
69
|
|
|
* данные контекста |
70
|
|
|
* |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
protected $contextInitializer = []; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Менеджер Initializer'ов |
77
|
|
|
* |
78
|
|
|
* @var FixtureInitializerManagerInterface |
79
|
|
|
*/ |
80
|
|
|
protected $fixtureInitializerManager; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Executor constructor. |
84
|
|
|
* |
85
|
|
|
* @param Configuration $configuration |
86
|
|
|
* @param FixtureExecutorBuilderInterface $fixtureExecutorBuilder |
87
|
|
|
* @param FixtureInitializerManagerInterface $fixtureInitializerManager |
88
|
|
|
*/ |
89
|
|
|
public function __construct( |
90
|
|
|
Configuration $configuration, |
91
|
|
|
FixtureExecutorBuilderInterface $fixtureExecutorBuilder, |
92
|
|
|
FixtureInitializerManagerInterface $fixtureInitializerManager |
93
|
|
|
) { |
94
|
|
|
$this->setFixtureInitializerManager($fixtureInitializerManager); |
95
|
|
|
$this->setConfiguration($configuration); |
96
|
|
|
$this->setFixtureExecutorBuilder($fixtureExecutorBuilder); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Возвращает компонент отвечающий за выполение фикстур |
101
|
|
|
* |
102
|
|
|
* @return FixtureExecutor |
103
|
|
|
*/ |
104
|
|
|
public function getFixtureExecutor() |
105
|
|
|
{ |
106
|
|
|
if (null !== $this->fixtureExecutor) { |
107
|
|
|
$this->fixtureExecutor; |
108
|
|
|
} |
109
|
|
|
$configuration = $this->getConfiguration(); |
110
|
|
|
$this->fixtureExecutor = $this->getFixtureExecutorBuilder()->build($configuration, $this); |
111
|
|
|
|
112
|
|
|
return $this->fixtureExecutor; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Возвращает загрузчик фикстур |
117
|
|
|
* |
118
|
|
|
* @return Loader |
119
|
|
|
*/ |
120
|
|
|
public function getLoader() |
121
|
|
|
{ |
122
|
|
|
if (null === $this->loader) { |
123
|
|
|
$this->loader = new ChainLoader(); |
124
|
|
|
} |
125
|
|
|
return $this->loader; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Устанавливает загрузчик фикстур |
130
|
|
|
* |
131
|
|
|
* @param Loader $loader |
132
|
|
|
* |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
|
|
public function setLoader(Loader $loader) |
136
|
|
|
{ |
137
|
|
|
$this->loader = $loader; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Возвращает фильтр фикстур |
144
|
|
|
* |
145
|
|
|
* @return Filter |
146
|
|
|
*/ |
147
|
|
|
public function getFilter() |
148
|
|
|
{ |
149
|
|
|
if (null === $this->filter) { |
150
|
|
|
$this->filter = new ChainFilter(); |
151
|
|
|
} |
152
|
|
|
return $this->filter; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Устанавливает фильтр фикстур |
157
|
|
|
* |
158
|
|
|
* @param Filter $filter |
159
|
|
|
* |
160
|
|
|
* @return $this |
161
|
|
|
*/ |
162
|
|
|
public function setFilter(Filter $filter) |
163
|
|
|
{ |
164
|
|
|
$this->filter = $filter; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Возвращает конфигурацию компонета отвечающего за выполнение фикстур |
171
|
|
|
* |
172
|
|
|
* @return Configuration |
173
|
|
|
*/ |
174
|
|
|
public function getConfiguration() |
175
|
|
|
{ |
176
|
|
|
return $this->configuration; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Устанавливает конфигурацию компонета отвечающего за выполнение фикстур |
181
|
|
|
* |
182
|
|
|
* @param Configuration $configuration |
183
|
|
|
* |
184
|
|
|
* @return $this |
185
|
|
|
*/ |
186
|
|
|
public function setConfiguration(Configuration $configuration) |
187
|
|
|
{ |
188
|
|
|
$this->configuration = $configuration; |
189
|
|
|
|
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @inheritdoc |
197
|
|
|
* |
198
|
|
|
* @return void |
199
|
|
|
*/ |
200
|
|
|
public function import(array $contextData = []) |
201
|
|
|
{ |
202
|
|
|
$this->execute(FixtureExecutor::IMPORT, $contextData); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Запускает фикстуры |
207
|
|
|
* |
208
|
|
|
* @param $method |
209
|
|
|
* @param array $contextData |
210
|
|
|
* |
211
|
|
|
* @return void |
212
|
|
|
*/ |
213
|
|
|
protected function execute($method, array $contextData = []) |
214
|
|
|
{ |
215
|
|
|
$loader = $this->getLoader(); |
216
|
|
|
$filter = $this->getFilter(); |
217
|
|
|
|
218
|
|
|
$contextInitializer = $this->getContextInitializer(); |
219
|
|
|
$fixtureInitializerManager = $this->getFixtureInitializerManager(); |
220
|
|
|
$eventManager = $this->getConfiguration()->getEventManager(); |
221
|
|
|
$initializers = []; |
222
|
|
|
foreach ($contextInitializer as $initializerName) { |
223
|
|
|
$initializer = $fixtureInitializerManager->get($initializerName, $contextData); |
|
|
|
|
224
|
|
|
$initializers[] = $initializer; |
225
|
|
|
$eventManager->addEventSubscriber($initializer); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$resourceLoaderInitializer = $fixtureInitializerManager->get(ResourceLoaderInitializer::class); |
229
|
|
|
$initializers[] = $resourceLoaderInitializer; |
230
|
|
|
$eventManager->addEventSubscriber($resourceLoaderInitializer); |
231
|
|
|
|
232
|
|
|
$this->getFixtureExecutor()->execute($loader, $filter, $method); |
233
|
|
|
|
234
|
|
|
foreach ($initializers as $initializer) { |
235
|
|
|
$eventManager->removeEventSubscriber($initializer); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @inheritdoc |
242
|
|
|
* |
243
|
|
|
* @return void |
244
|
|
|
*/ |
245
|
|
|
public function purge(array $contextData = []) |
246
|
|
|
{ |
247
|
|
|
$this->execute(FixtureExecutor::PURGE, $contextData); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Возвращает имя |
252
|
|
|
* |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getName() |
256
|
|
|
{ |
257
|
|
|
return $this->name; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Устанавливает имя |
262
|
|
|
* |
263
|
|
|
* @param string $name |
264
|
|
|
* |
265
|
|
|
* @return $this |
266
|
|
|
*/ |
267
|
|
|
public function setName($name) |
268
|
|
|
{ |
269
|
|
|
$this->name = (string)$name; |
270
|
|
|
|
271
|
|
|
return $this; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Возвращает сервис, отвечающий за создание компонента выполняющего фикстуры |
276
|
|
|
* |
277
|
|
|
* @return FixtureExecutorBuilderInterface |
278
|
|
|
*/ |
279
|
|
|
public function getFixtureExecutorBuilder() |
280
|
|
|
{ |
281
|
|
|
return $this->fixtureExecutorBuilder; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Устанавливает сервис, отвечающий за создание компонента выполняющего фикстуры |
286
|
|
|
* |
287
|
|
|
* @param FixtureExecutorBuilderInterface $fixtureExecutorBuilder |
288
|
|
|
* |
289
|
|
|
* @return $this |
290
|
|
|
*/ |
291
|
|
|
public function setFixtureExecutorBuilder(FixtureExecutorBuilderInterface $fixtureExecutorBuilder) |
292
|
|
|
{ |
293
|
|
|
$this->fixtureExecutorBuilder = $fixtureExecutorBuilder; |
294
|
|
|
|
295
|
|
|
return $this; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Возвращает инициалайзеры, создаваемые заново перед каждым запуском фикстур. При создание этих инициайзеров, им передаются |
301
|
|
|
* данные контекста |
302
|
|
|
* |
303
|
|
|
* @return array |
304
|
|
|
*/ |
305
|
|
|
public function getContextInitializer() |
306
|
|
|
{ |
307
|
|
|
return $this->contextInitializer; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Устанавлиает инициалайзеры, создаваемые заново перед каждым запуском фикстур. При создание этих инициайзеров, им передаются |
312
|
|
|
* данные контекста |
313
|
|
|
* |
314
|
|
|
* @param array $contextInitializer |
315
|
|
|
* |
316
|
|
|
* @return $this |
317
|
|
|
*/ |
318
|
|
|
public function setContextInitializer($contextInitializer) |
319
|
|
|
{ |
320
|
|
|
$this->contextInitializer = $contextInitializer; |
321
|
|
|
|
322
|
|
|
return $this; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Возвращает менеджер Initializer'ов |
327
|
|
|
* |
328
|
|
|
* @return FixtureInitializerManagerInterface |
329
|
|
|
*/ |
330
|
|
|
public function getFixtureInitializerManager() |
331
|
|
|
{ |
332
|
|
|
return $this->fixtureInitializerManager; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Устанавливает менеджер Initializer'ов |
337
|
|
|
* |
338
|
|
|
* @param FixtureInitializerManagerInterface $fixtureInitializerManager |
339
|
|
|
* |
340
|
|
|
* @return $this |
341
|
|
|
*/ |
342
|
|
|
public function setFixtureInitializerManager(FixtureInitializerManagerInterface $fixtureInitializerManager) |
343
|
|
|
{ |
344
|
|
|
$this->fixtureInitializerManager = $fixtureInitializerManager; |
345
|
|
|
|
346
|
|
|
return $this; |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.