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\Executor as FixtureExecutor; |
9
|
|
|
use Doctrine\Fixture\Configuration; |
10
|
|
|
use Nnx\DoctrineFixtureModule\Listener\ExecuteEventSubscriberInterface; |
11
|
|
|
use Nnx\DoctrineFixtureModule\Listener\PostExecuteEventSubscriber; |
12
|
|
|
use Nnx\DoctrineFixtureModule\Listener\PreExecuteEventSubscriber; |
13
|
|
|
use Nnx\DoctrineFixtureModule\Listener\RunFixtureEventSubscriber; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class FixtureExecutorBuilder |
17
|
|
|
* |
18
|
|
|
* @package Nnx\DoctrineFixtureModule\Executor |
19
|
|
|
*/ |
20
|
|
|
class FixtureExecutorBuilder implements FixtureExecutorBuilderInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Прототип для обработчика событий возникающий после начала выполнения циккла диспетчиризации фикстур |
24
|
|
|
* |
25
|
|
|
* @var ExecuteEventSubscriberInterface |
26
|
|
|
*/ |
27
|
|
|
protected $postExecuteEventSubscriberPrototype; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Прототип для обработчика событий возникающий перед началом выполнения циккла диспетчиризации фикстур |
31
|
|
|
* |
32
|
|
|
* @var ExecuteEventSubscriberInterface |
33
|
|
|
*/ |
34
|
|
|
protected $preExecuteEventSubscriberPrototype; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Прототип для обарботчика события возникающего перед запуском фикстуры |
38
|
|
|
* |
39
|
|
|
* @var ExecuteEventSubscriberInterface |
40
|
|
|
*/ |
41
|
|
|
protected $runFixtureEventSubscriber; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritdoc |
45
|
|
|
* |
46
|
|
|
* @param Configuration $configuration |
47
|
|
|
* |
48
|
|
|
* @return FixtureExecutor |
49
|
|
|
*/ |
50
|
|
|
public function build(Configuration $configuration, ExecutorInterface $executor) |
51
|
|
|
{ |
52
|
|
|
$eventManager = $configuration->getEventManager(); |
53
|
|
|
|
54
|
|
|
$preExecuteEventSubscriberPrototype = clone $this->getPreExecuteEventSubscriberPrototype(); |
55
|
|
|
$preExecuteEventSubscriberPrototype->setExecutor($executor); |
56
|
|
|
$eventManager->addEventSubscriber($preExecuteEventSubscriberPrototype); |
57
|
|
|
|
58
|
|
|
$runFixtureEventSubscriber = clone $this->getRunFixtureEventSubscriber(); |
59
|
|
|
$runFixtureEventSubscriber->setExecutor($executor); |
60
|
|
|
$eventManager->addEventSubscriber($runFixtureEventSubscriber); |
61
|
|
|
|
62
|
|
|
$doctrineFixtureExecutor = new FixtureExecutor($configuration); |
63
|
|
|
|
64
|
|
|
$postExecuteEventSubscriberPrototype = clone $this->getPostExecuteEventSubscriberPrototype(); |
65
|
|
|
$postExecuteEventSubscriberPrototype->setExecutor($executor); |
66
|
|
|
$eventManager->addEventSubscriber($postExecuteEventSubscriberPrototype); |
67
|
|
|
|
68
|
|
|
return $doctrineFixtureExecutor; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Возвращает прототип для обработчика событий возникающий после начала выполнения циккла диспетчиризации фикстур |
73
|
|
|
* |
74
|
|
|
* @return ExecuteEventSubscriberInterface |
75
|
|
|
*/ |
76
|
|
|
public function getPostExecuteEventSubscriberPrototype() |
77
|
|
|
{ |
78
|
|
|
if (null === $this->postExecuteEventSubscriberPrototype) { |
79
|
|
|
$postExecuteEventSubscriberPrototype = new PostExecuteEventSubscriber(); |
80
|
|
|
$this->setPostExecuteEventSubscriberPrototype($postExecuteEventSubscriberPrototype); |
81
|
|
|
} |
82
|
|
|
return $this->postExecuteEventSubscriberPrototype; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Устанавливает прототип для обработчика событий возникающий после начала выполнения циккла диспетчиризации фикстур |
87
|
|
|
* |
88
|
|
|
* @param ExecuteEventSubscriberInterface $postExecuteEventSubscriberPrototype |
89
|
|
|
* |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
|
|
public function setPostExecuteEventSubscriberPrototype(ExecuteEventSubscriberInterface $postExecuteEventSubscriberPrototype) |
93
|
|
|
{ |
94
|
|
|
$this->postExecuteEventSubscriberPrototype = $postExecuteEventSubscriberPrototype; |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Возвращает прототип для обработчика событий возникающий перед началом выполнения циккла диспетчиризации фикстур |
101
|
|
|
* |
102
|
|
|
* @return ExecuteEventSubscriberInterface |
103
|
|
|
*/ |
104
|
|
|
public function getPreExecuteEventSubscriberPrototype() |
105
|
|
|
{ |
106
|
|
|
if (null === $this->preExecuteEventSubscriberPrototype) { |
107
|
|
|
$preExecuteEventSubscriberPrototype = new PreExecuteEventSubscriber(); |
108
|
|
|
$this->setPreExecuteEventSubscriberPrototype($preExecuteEventSubscriberPrototype); |
109
|
|
|
} |
110
|
|
|
return $this->preExecuteEventSubscriberPrototype; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Устанавливает прототип для обработчика событий возникающий перед началом выполнения циккла диспетчиризации фикстур |
115
|
|
|
* |
116
|
|
|
* @param ExecuteEventSubscriberInterface $preExecuteEventSubscriberPrototype |
117
|
|
|
* |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
|
|
public function setPreExecuteEventSubscriberPrototype(ExecuteEventSubscriberInterface $preExecuteEventSubscriberPrototype) |
121
|
|
|
{ |
122
|
|
|
$this->preExecuteEventSubscriberPrototype = $preExecuteEventSubscriberPrototype; |
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Возвращает прототип для обарботчика события возникающего перед запуском фикстуры |
129
|
|
|
* |
130
|
|
|
* @return ExecuteEventSubscriberInterface |
131
|
|
|
*/ |
132
|
|
|
public function getRunFixtureEventSubscriber() |
133
|
|
|
{ |
134
|
|
|
if (null === $this->runFixtureEventSubscriber) { |
135
|
|
|
$runFixtureEventSubscriber = new RunFixtureEventSubscriber(); |
136
|
|
|
$this->setRunFixtureEventSubscriber($runFixtureEventSubscriber); |
137
|
|
|
} |
138
|
|
|
return $this->runFixtureEventSubscriber; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Устанавливает прототип для обарботчика события возникающего перед запуском фикстуры |
143
|
|
|
* |
144
|
|
|
* @param ExecuteEventSubscriberInterface $runFixtureEventSubscriber |
145
|
|
|
* |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
|
|
public function setRunFixtureEventSubscriber(ExecuteEventSubscriberInterface $runFixtureEventSubscriber) |
149
|
|
|
{ |
150
|
|
|
$this->runFixtureEventSubscriber = $runFixtureEventSubscriber; |
151
|
|
|
|
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|