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