1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Abacaphiliac\Zend\EventManager\PluginManager; |
4
|
|
|
|
5
|
|
|
use Zend\ModuleManager\Listener\ServiceListenerInterface; |
6
|
|
|
use Zend\ModuleManager\ModuleManager; |
7
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
8
|
|
|
|
9
|
|
|
class Module |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return mixed[] |
13
|
|
|
*/ |
14
|
5 |
|
public function getConfig() |
15
|
|
|
{ |
16
|
5 |
|
return include __DIR__ . '/../../config/module.config.php'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param ModuleManager $moduleManager |
21
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
22
|
|
|
*/ |
23
|
5 |
|
public function init(ModuleManager $moduleManager) |
24
|
|
|
{ |
25
|
5 |
|
$moduleEvent = $moduleManager->getEvent(); |
26
|
|
|
|
27
|
|
|
/** @var ServiceLocatorInterface $serviceLocator */ |
28
|
5 |
|
$serviceLocator = $moduleEvent->getParam('ServiceManager'); |
29
|
|
|
|
30
|
|
|
/** @var ServiceListenerInterface $serviceListener */ |
31
|
5 |
|
$serviceListener = $serviceLocator->get('ServiceListener'); |
32
|
|
|
|
33
|
|
|
// Register EventManagers plugin manager. |
34
|
5 |
|
static::registerPluginManager($serviceListener); |
35
|
|
|
|
36
|
|
|
// Register ListenerAggregates plugin manager. |
37
|
5 |
|
static::registerListenerAggregatesPluginManager($serviceListener); |
38
|
5 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ServiceListenerInterface $serviceListener |
42
|
|
|
* @return ServiceListenerInterface |
43
|
|
|
*/ |
44
|
6 |
|
public static function registerPluginManager(ServiceListenerInterface $serviceListener) |
45
|
|
|
{ |
46
|
6 |
|
return $serviceListener->addServiceManager( |
47
|
|
|
// The name of the plugin manager as it is configured in the service manager, |
48
|
|
|
// all config is injected into this instance of the plugin manager. |
49
|
6 |
|
'EventManagers', |
50
|
|
|
// The key which is read from the merged module.config.php files, the |
51
|
|
|
// contents of this key are used as services for the plugin manager. |
52
|
6 |
|
'event_managers', |
53
|
|
|
// The interface which can be specified on a Module class for injecting |
54
|
|
|
// services into the plugin manager, using this interface in a Module |
55
|
|
|
// class is optional and depending on how your auto-loader is configured |
56
|
|
|
// it may not work correctly. |
57
|
6 |
|
'\Abacaphiliac\Zend\EventManager\PluginManager\EventManagersProviderInterface', |
58
|
|
|
// The function specified by the above interface, the return value of this |
59
|
|
|
// function is merged with the config from 'sample_plugins_config_key'. |
60
|
|
|
'getEventManagersConfig' |
61
|
6 |
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param ServiceListenerInterface $serviceListener |
66
|
|
|
* @return ServiceListenerInterface |
67
|
|
|
*/ |
68
|
5 |
|
public static function registerListenerAggregatesPluginManager(ServiceListenerInterface $serviceListener) |
69
|
|
|
{ |
70
|
5 |
|
return $serviceListener->addServiceManager( |
71
|
|
|
// The name of the plugin manager as it is configured in the service manager, |
72
|
|
|
// all config is injected into this instance of the plugin manager. |
73
|
5 |
|
'ListenerAggregates', |
74
|
|
|
// The key which is read from the merged module.config.php files, the |
75
|
|
|
// contents of this key are used as services for the plugin manager. |
76
|
5 |
|
'listener_aggregates', |
77
|
|
|
// The interface which can be specified on a Module class for injecting |
78
|
|
|
// services into the plugin manager, using this interface in a Module |
79
|
|
|
// class is optional and depending on how your auto-loader is configured |
80
|
|
|
// it may not work correctly. |
81
|
5 |
|
'\Abacaphiliac\Zend\EventManager\PluginManager\ListenerAggregate\ListenerAggregatesProviderInterface', |
82
|
|
|
// The function specified by the above interface, the return value of this |
83
|
|
|
// function is merged with the config from 'sample_plugins_config_key'. |
84
|
|
|
'getListenerAggregatesConfig' |
85
|
5 |
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|