1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/jms-serializer-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\JmsSerializerModule; |
7
|
|
|
|
8
|
|
|
use Nnx\ModuleOptions\ModuleConfigKeyProviderInterface; |
9
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
10
|
|
|
use Zend\ModuleManager\Feature\DependencyIndicatorInterface; |
11
|
|
|
use Zend\ModuleManager\Listener\ServiceListenerInterface; |
12
|
|
|
use Zend\ModuleManager\ModuleManager; |
13
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
14
|
|
|
use Zend\Mvc\ModuleRouteListener; |
15
|
|
|
use Zend\Mvc\MvcEvent; |
16
|
|
|
use Zend\EventManager\EventInterface; |
17
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
18
|
|
|
use Zend\ModuleManager\Feature\BootstrapListenerInterface; |
19
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
20
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
21
|
|
|
use Nnx\ModuleOptions\Module as ModuleOptions; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Module |
25
|
|
|
* |
26
|
|
|
* @package Nnx\JmsSerializerModule |
27
|
|
|
*/ |
28
|
|
|
class Module implements |
29
|
|
|
BootstrapListenerInterface, |
30
|
|
|
AutoloaderProviderInterface, |
31
|
|
|
InitProviderInterface, |
32
|
|
|
ConfigProviderInterface, |
33
|
|
|
ModuleConfigKeyProviderInterface, |
34
|
|
|
DependencyIndicatorInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Имя секции в конфиги приложения отвечающей за настройки модуля |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
const CONFIG_KEY = 'nnx_jms_serializer'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Имя секции в конфиги приложения отвечающей за настройки сервис менеджера для данного модуля |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
const MODULE_SERVICE_MANAGER_CONFIG_KEY = 'nnx_jms_serializer_service'; |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Имя модуля |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
const MODULE_NAME = __NAMESPACE__; |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
*/ |
62
|
|
|
public function getModuleDependencies() |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
ModuleOptions::MODULE_NAME |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getModuleConfigKey() |
75
|
|
|
{ |
76
|
|
|
return static::CONFIG_KEY; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param ModuleManagerInterface $manager |
82
|
|
|
* |
83
|
|
|
* @throws Exception\InvalidArgumentException |
84
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
85
|
|
|
*/ |
86
|
|
|
public function init(ModuleManagerInterface $manager) |
87
|
|
|
{ |
88
|
|
|
if (!$manager instanceof ModuleManager) { |
89
|
|
|
$errMsg = sprintf('Module manager not implement %s', ModuleManager::class); |
90
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** @var ServiceLocatorInterface $sm */ |
94
|
|
|
$sm = $manager->getEvent()->getParam('ServiceManager'); |
95
|
|
|
|
96
|
|
|
if (!$sm instanceof ServiceLocatorInterface) { |
97
|
|
|
$errMsg = sprintf('Service locator not implement %s', ServiceLocatorInterface::class); |
98
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
99
|
|
|
} |
100
|
|
|
/** @var ServiceListenerInterface $serviceListener */ |
101
|
|
|
$serviceListener = $sm->get('ServiceListener'); |
102
|
|
|
if (!$serviceListener instanceof ServiceListenerInterface) { |
103
|
|
|
$errMsg = sprintf('ServiceListener not implement %s', ServiceListenerInterface::class); |
104
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @inheritdoc |
112
|
|
|
* |
113
|
|
|
* @param EventInterface $e |
114
|
|
|
* |
115
|
|
|
* @return array|void |
116
|
|
|
* |
117
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
118
|
|
|
*/ |
119
|
|
|
public function onBootstrap(EventInterface $e) |
120
|
|
|
{ |
121
|
|
|
/** @var MvcEvent $e */ |
122
|
|
|
$eventManager = $e->getApplication()->getEventManager(); |
123
|
|
|
$moduleRouteListener = new ModuleRouteListener(); |
124
|
|
|
$moduleRouteListener->attach($eventManager); |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
|
|
public function getAutoloaderConfig() |
133
|
|
|
{ |
134
|
|
|
return [ |
135
|
|
|
'Zend\Loader\StandardAutoloader' => [ |
136
|
|
|
'namespaces' => [ |
137
|
|
|
__NAMESPACE__ => __DIR__ . '/src/', |
138
|
|
|
], |
139
|
|
|
], |
140
|
|
|
]; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @inheritdoc |
146
|
|
|
* |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
|
|
public function getConfig() |
150
|
|
|
{ |
151
|
|
|
return array_merge_recursive( |
152
|
|
|
include __DIR__ . '/config/module.config.php', |
153
|
|
|
include __DIR__ . '/config/serviceManager.config.php', |
154
|
|
|
include __DIR__ . '/config/serializer.config.php', |
155
|
|
|
include __DIR__ . '/config/moduleServiceManager.config.php' |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
} |