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