This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathModuleManagerFactory.php
97 lines (86 loc) · 3.56 KB
/
ModuleManagerFactory.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
<?php
/**
* @link http://github.com/zendframework/zend-mvc for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Mvc\Service;
use Interop\Container\ContainerInterface;
use Zend\ModuleManager\Listener\DefaultListenerAggregate;
use Zend\ModuleManager\Listener\ListenerOptions;
use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;
use Zend\ServiceManager\Factory\FactoryInterface;
class ModuleManagerFactory implements FactoryInterface
{
/**
* Creates and returns the module manager
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ContainerInterface $container
* @param string $name
* @param null|array $options
* @return ModuleManager
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
$configuration = $container->get('ApplicationConfig');
$defaultListeners = $container->has(DefaultListenerAggregate::class)
? $container->get(DefaultListenerAggregate::class)
: $this->createDefaultListener($container);
$serviceListener = $container->get('ServiceListener');
$serviceListener->addServiceManager(
$container,
'service_manager',
'Zend\ModuleManager\Feature\ServiceProviderInterface',
'getServiceConfig'
);
$serviceListener->addServiceManager(
'ControllerManager',
'controllers',
'Zend\ModuleManager\Feature\ControllerProviderInterface',
'getControllerConfig'
);
$serviceListener->addServiceManager(
'ControllerPluginManager',
'controller_plugins',
'Zend\ModuleManager\Feature\ControllerPluginProviderInterface',
'getControllerPluginConfig'
);
$serviceListener->addServiceManager(
'ViewHelperManager',
'view_helpers',
'Zend\ModuleManager\Feature\ViewHelperProviderInterface',
'getViewHelperConfig'
);
$serviceListener->addServiceManager(
'RoutePluginManager',
'route_manager',
'Zend\ModuleManager\Feature\RouteProviderInterface',
'getRouteConfig'
);
$events = $container->get('EventManager');
$defaultListeners->attach($events);
$serviceListener->attach($events);
$moduleEvent = new ModuleEvent;
$moduleEvent->setParam('ServiceManager', $container);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
private function createDefaultListener(ContainerInterface $container)
{
$configuration = $container->get('ApplicationConfig');
$listenerOptions = $container->has(ListenerOptions::class)
? $container->get(ListenerOptions::class)
: new ListenerOptions($configuration['module_listener_options']);
return new DefaultListenerAggregate($listenerOptions);
}
}