3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mvc\Service
;
12 use Interop\Container\ContainerInterface
;
13 use Zend\ModuleManager\Listener\DefaultListenerAggregate
;
14 use Zend\ModuleManager\Listener\ListenerOptions
;
15 use Zend\ModuleManager\ModuleEvent
;
16 use Zend\ModuleManager\ModuleManager
;
17 use Zend\ServiceManager\FactoryInterface
;
18 use Zend\ServiceManager\ServiceLocatorInterface
;
20 class ModuleManagerFactory
implements FactoryInterface
23 * Creates and returns the module manager
25 * Instantiates the default module listeners, providing them configuration
26 * from the "module_listener_options" key of the ApplicationConfig
27 * service. Also sets the default config glob path.
29 * Module manager is instantiated and provided with an EventManager, to which
30 * the default listener aggregate is attached. The ModuleEvent is also created
31 * and attached to the module manager.
33 * @param ContainerInterface $container
35 * @param null|array $options
36 * @return ModuleManager
38 public function __invoke(ContainerInterface
$container, $name, array $options = null)
40 $configuration = $container->get('ApplicationConfig');
41 $listenerOptions = new ListenerOptions($configuration['module_listener_options']);
42 $defaultListeners = new DefaultListenerAggregate($listenerOptions);
43 $serviceListener = $container->get('ServiceListener');
45 $serviceListener->addServiceManager(
48 'Zend\ModuleManager\Feature\ServiceProviderInterface',
52 $serviceListener->addServiceManager(
55 'Zend\ModuleManager\Feature\ControllerProviderInterface',
58 $serviceListener->addServiceManager(
59 'ControllerPluginManager',
61 'Zend\ModuleManager\Feature\ControllerPluginProviderInterface',
62 'getControllerPluginConfig'
64 $serviceListener->addServiceManager(
67 'Zend\ModuleManager\Feature\ViewHelperProviderInterface',
70 $serviceListener->addServiceManager(
73 'Zend\ModuleManager\Feature\ValidatorProviderInterface',
76 $serviceListener->addServiceManager(
79 'Zend\ModuleManager\Feature\FilterProviderInterface',
82 $serviceListener->addServiceManager(
85 'Zend\ModuleManager\Feature\FormElementProviderInterface',
86 'getFormElementConfig'
88 $serviceListener->addServiceManager(
91 'Zend\ModuleManager\Feature\RouteProviderInterface',
94 $serviceListener->addServiceManager(
95 'SerializerAdapterManager',
97 'Zend\ModuleManager\Feature\SerializerProviderInterface',
100 $serviceListener->addServiceManager(
103 'Zend\ModuleManager\Feature\HydratorProviderInterface',
106 $serviceListener->addServiceManager(
107 'InputFilterManager',
109 'Zend\ModuleManager\Feature\InputFilterProviderInterface',
110 'getInputFilterConfig'
112 $serviceListener->addServiceManager(
113 'LogProcessorManager',
115 'Zend\ModuleManager\Feature\LogProcessorProviderInterface',
116 'getLogProcessorConfig'
118 $serviceListener->addServiceManager(
121 'Zend\ModuleManager\Feature\LogWriterProviderInterface',
124 $serviceListener->addServiceManager(
125 'TranslatorPluginManager',
126 'translator_plugins',
127 'Zend\ModuleManager\Feature\TranslatorPluginProviderInterface',
128 'getTranslatorPluginConfig'
131 $events = $container->get('EventManager');
132 $defaultListeners->attach($events);
133 $serviceListener->attach($events);
135 $moduleEvent = new ModuleEvent
;
136 $moduleEvent->setParam('ServiceManager', $container);
138 $moduleManager = new ModuleManager($configuration['modules'], $events);
139 $moduleManager->setEvent($moduleEvent);
141 return $moduleManager;
145 * Create and return ModuleManager instance
147 * For use with zend-servicemanager v2; proxies to __invoke().
149 * @param ServiceLocatorInterface $container
150 * @return ModuleManager
152 public function createService(ServiceLocatorInterface
$container)
154 return $this($container, ModuleManager
::class);