3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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 Zend\ModuleManager\Listener\DefaultListenerAggregate
;
13 use Zend\ModuleManager\Listener\ListenerOptions
;
14 use Zend\ModuleManager\ModuleEvent
;
15 use Zend\ModuleManager\ModuleManager
;
16 use Zend\ServiceManager\FactoryInterface
;
17 use Zend\ServiceManager\ServiceLocatorInterface
;
19 class ModuleManagerFactory
implements FactoryInterface
22 * Creates and returns the module manager
24 * Instantiates the default module listeners, providing them configuration
25 * from the "module_listener_options" key of the ApplicationConfig
26 * service. Also sets the default config glob path.
28 * Module manager is instantiated and provided with an EventManager, to which
29 * the default listener aggregate is attached. The ModuleEvent is also created
30 * and attached to the module manager.
32 * @param ServiceLocatorInterface $serviceLocator
33 * @return ModuleManager
35 public function createService(ServiceLocatorInterface
$serviceLocator)
37 if (!$serviceLocator->has('ServiceListener')) {
38 $serviceLocator->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory');
41 $configuration = $serviceLocator->get('ApplicationConfig');
42 $listenerOptions = new ListenerOptions($configuration['module_listener_options']);
43 $defaultListeners = new DefaultListenerAggregate($listenerOptions);
44 $serviceListener = $serviceLocator->get('ServiceListener');
46 $serviceListener->addServiceManager(
49 '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'
113 $events = $serviceLocator->get('EventManager');
114 $events->attach($defaultListeners);
115 $events->attach($serviceListener);
117 $moduleEvent = new ModuleEvent
;
118 $moduleEvent->setParam('ServiceManager', $serviceLocator);
120 $moduleManager = new ModuleManager($configuration['modules'], $events);
121 $moduleManager->setEvent($moduleEvent);
123 return $moduleManager;