1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine-fixture-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\DoctrineFixtureModule; |
7
|
|
|
|
8
|
|
|
use Nnx\DoctrineFixtureModule\FilterUsedFixtureService\FilterUsedFixtureListener; |
9
|
|
|
use Nnx\DoctrineFixtureModule\FixtureInitializer\FixtureInitializerManager; |
10
|
|
|
use Nnx\DoctrineFixtureModule\FixtureInitializer\FixtureInitializerManagerInterface; |
11
|
|
|
use Nnx\DoctrineFixtureModule\FixtureInitializer\FixtureInitializerProviderInterface; |
12
|
|
|
use Nnx\DoctrineFixtureModule\ResourceLoader\ResourceLoaderManager; |
13
|
|
|
use Nnx\DoctrineFixtureModule\ResourceLoader\ResourceLoaderManagerInterface; |
14
|
|
|
use Nnx\DoctrineFixtureModule\ResourceLoader\ResourceLoaderProviderInterface; |
15
|
|
|
use Nnx\ModuleOptions\ModuleConfigKeyProviderInterface; |
16
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
17
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
18
|
|
|
use Zend\ModuleManager\Listener\ServiceListenerInterface; |
19
|
|
|
use Zend\ModuleManager\ModuleManager; |
20
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
21
|
|
|
use Zend\Mvc\ModuleRouteListener; |
22
|
|
|
use Zend\Mvc\MvcEvent; |
23
|
|
|
use Zend\EventManager\EventInterface; |
24
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
25
|
|
|
use Zend\ModuleManager\Feature\BootstrapListenerInterface; |
26
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
27
|
|
|
use Zend\ModuleManager\Feature\DependencyIndicatorInterface; |
28
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
29
|
|
|
use Nnx\DoctrineFixtureModule\Loader\FixtureLoaderManagerInterface; |
30
|
|
|
use Nnx\DoctrineFixtureModule\Loader\FixtureLoaderManager; |
31
|
|
|
use Nnx\DoctrineFixtureModule\Loader\FixtureLoaderProviderInterface; |
32
|
|
|
use Nnx\DoctrineFixtureModule\Filter\FixtureFilterManagerInterface; |
33
|
|
|
use Nnx\DoctrineFixtureModule\Filter\FixtureFilterManager; |
34
|
|
|
use Nnx\DoctrineFixtureModule\Filter\FixtureFilterProviderInterface; |
35
|
|
|
use Nnx\DoctrineFixtureModule\Executor\FixtureExecutorManagerInterface; |
36
|
|
|
use Nnx\DoctrineFixtureModule\Executor\FixtureExecutorManager; |
37
|
|
|
use Nnx\DoctrineFixtureModule\Executor\FixtureExecutorProviderInterface; |
38
|
|
|
use Nnx\ModuleOptions\Module as ModuleOptions; |
39
|
|
|
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface; |
40
|
|
|
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Class Module |
44
|
|
|
* |
45
|
|
|
* @package Nnx\DoctrineFixtureModule |
46
|
|
|
*/ |
47
|
|
|
class Module implements |
48
|
|
|
BootstrapListenerInterface, |
49
|
|
|
AutoloaderProviderInterface, |
50
|
|
|
InitProviderInterface, |
51
|
|
|
ConfigProviderInterface, |
52
|
|
|
ModuleConfigKeyProviderInterface, |
53
|
|
|
DependencyIndicatorInterface, |
54
|
|
|
ConsoleUsageProviderInterface, |
55
|
|
|
ConsoleBannerProviderInterface |
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* Имя секции в конфиги приложения отвечающей за настройки модуля |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
const CONFIG_KEY = 'nnx_doctrine_fixture_module'; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Имя модуля |
66
|
|
|
* |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
const MODULE_NAME = __NAMESPACE__; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function getModuleDependencies() |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
ModuleOptions::MODULE_NAME |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @inheritDoc |
84
|
|
|
*/ |
85
|
|
|
public function getModuleConfigKey() |
86
|
|
|
{ |
87
|
|
|
return static::CONFIG_KEY; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param ModuleManagerInterface $manager |
92
|
|
|
* |
93
|
|
|
* @throws Exception\InvalidArgumentException |
94
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
95
|
|
|
*/ |
96
|
|
|
public function init(ModuleManagerInterface $manager) |
97
|
|
|
{ |
98
|
|
|
if (!$manager instanceof ModuleManager) { |
99
|
|
|
$errMsg =sprintf('Module manager not implement %s', ModuleManager::class); |
100
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** @var ServiceLocatorInterface $sm */ |
104
|
|
|
$sm = $manager->getEvent()->getParam('ServiceManager'); |
105
|
|
|
|
106
|
|
|
if (!$sm instanceof ServiceLocatorInterface) { |
107
|
|
|
$errMsg = sprintf('Service locator not implement %s', ServiceLocatorInterface::class); |
108
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
109
|
|
|
} |
110
|
|
|
/** @var ServiceListenerInterface $serviceListener */ |
111
|
|
|
$serviceListener = $sm->get('ServiceListener'); |
112
|
|
|
if (!$serviceListener instanceof ServiceListenerInterface) { |
113
|
|
|
$errMsg = sprintf('ServiceListener not implement %s', ServiceListenerInterface::class); |
114
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$serviceListener->addServiceManager( |
118
|
|
|
FixtureLoaderManagerInterface::class, |
119
|
|
|
FixtureLoaderManager::CONFIG_KEY, |
120
|
|
|
FixtureLoaderProviderInterface::class, |
121
|
|
|
'getFixtureLoaderConfig' |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$serviceListener->addServiceManager( |
125
|
|
|
FixtureFilterManagerInterface::class, |
126
|
|
|
FixtureFilterManager::CONFIG_KEY, |
127
|
|
|
FixtureFilterProviderInterface::class, |
128
|
|
|
'getFixtureFilterConfig' |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$serviceListener->addServiceManager( |
132
|
|
|
FixtureExecutorManagerInterface::class, |
133
|
|
|
FixtureExecutorManager::CONFIG_KEY, |
134
|
|
|
FixtureExecutorProviderInterface::class, |
135
|
|
|
'getFixtureExecutorConfig' |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$serviceListener->addServiceManager( |
139
|
|
|
FixtureInitializerManagerInterface::class, |
140
|
|
|
FixtureInitializerManager::CONFIG_KEY, |
141
|
|
|
FixtureInitializerProviderInterface::class, |
142
|
|
|
'getFixtureInitializerConfig' |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$serviceListener->addServiceManager( |
146
|
|
|
ResourceLoaderManagerInterface::class, |
147
|
|
|
ResourceLoaderManager::CONFIG_KEY, |
148
|
|
|
ResourceLoaderProviderInterface::class, |
149
|
|
|
'getResourceLoaderConfig' |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritdoc |
155
|
|
|
* |
156
|
|
|
* @param EventInterface $e |
157
|
|
|
* |
158
|
|
|
* @return array|void |
159
|
|
|
* @throws \Nnx\DoctrineFixtureModule\Exception\InvalidArgumentException |
160
|
|
|
* |
161
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
162
|
|
|
*/ |
163
|
|
|
public function onBootstrap(EventInterface $e) |
164
|
|
|
{ |
165
|
|
|
if (!$e instanceof MvcEvent) { |
166
|
|
|
$errMsg =sprintf('Event not implement %s', MvcEvent::class); |
167
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
$app = $e->getApplication(); |
171
|
|
|
|
172
|
|
|
$eventManager = $app->getEventManager(); |
173
|
|
|
$moduleRouteListener = new ModuleRouteListener(); |
174
|
|
|
$moduleRouteListener->attach($eventManager); |
175
|
|
|
|
176
|
|
|
$sl = $app->getServiceManager(); |
177
|
|
|
|
178
|
|
|
/** @var FilterUsedFixtureListener$filterUsedFixtureListener */ |
179
|
|
|
$filterUsedFixtureListener = $sl->get(FilterUsedFixtureListener::class); |
180
|
|
|
$filterUsedFixtureListener->attach($eventManager); |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return array |
188
|
|
|
*/ |
189
|
|
|
public function getAutoloaderConfig() |
190
|
|
|
{ |
191
|
|
|
return [ |
192
|
|
|
'Zend\Loader\StandardAutoloader' => [ |
193
|
|
|
'namespaces' => [ |
194
|
|
|
__NAMESPACE__ => __DIR__ . '/src/', |
195
|
|
|
], |
196
|
|
|
], |
197
|
|
|
]; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @inheritdoc |
203
|
|
|
* |
204
|
|
|
* @return array |
205
|
|
|
*/ |
206
|
|
|
public function getConfig() |
207
|
|
|
{ |
208
|
|
|
return array_merge_recursive( |
209
|
|
|
include __DIR__ . '/config/serviceManager.config.php', |
210
|
|
|
include __DIR__ . '/config/fixtureLoader.config.php', |
211
|
|
|
include __DIR__ . '/config/fixtureFilter.config.php', |
212
|
|
|
include __DIR__ . '/config/fixtureExecutor.config.php', |
213
|
|
|
include __DIR__ . '/config/doctrine.config.php', |
214
|
|
|
include __DIR__ . '/config/controllers.config.php', |
215
|
|
|
include __DIR__ . '/config/console.config.php', |
216
|
|
|
include __DIR__ . '/config/fixtureInitializer.config.php', |
217
|
|
|
include __DIR__ . '/config/resourceLoader.config.php', |
218
|
|
|
include __DIR__ . '/config/module.config.php' |
219
|
|
|
|
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @inheritDoc |
225
|
|
|
*/ |
226
|
|
|
public function getConsoleUsage(AdapterInterface $console) |
227
|
|
|
{ |
228
|
|
|
return [ |
229
|
|
|
'Doctrine data fixture', |
230
|
|
|
'nnx:fixture execute-fixture --fixtureClassName=' => 'Run fixture bu class name', |
231
|
|
|
['--fixtureClassName=FIXTURE_CLASS_NAME', 'Fixture class name'], |
232
|
|
|
'nnx:fixture run-executor --executorName=' => 'Run fixture executor by name', |
233
|
|
|
['--executorName==EXECUTOR_NAME', 'Executor name'], |
234
|
|
|
]; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @inheritDoc |
239
|
|
|
*/ |
240
|
|
|
public function getConsoleBanner(AdapterInterface $console) |
241
|
|
|
{ |
242
|
|
|
return 'Doctrine fixture tools'; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
} |