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