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