PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zendframework/library/Zend/Mvc/Service/ModuleManagerFactory.php

https://bitbucket.org/pcelta/zf2
PHP | 89 lines | 53 code | 9 blank | 27 comment | 1 complexity | 2104a016a03898540d6164b7ed197ca4 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Mvc
  9. */
  10. namespace Zend\Mvc\Service;
  11. use Zend\ModuleManager\Listener\DefaultListenerAggregate;
  12. use Zend\ModuleManager\Listener\ListenerOptions;
  13. use Zend\ModuleManager\ModuleEvent;
  14. use Zend\ModuleManager\ModuleManager;
  15. use Zend\ServiceManager\FactoryInterface;
  16. use Zend\ServiceManager\ServiceLocatorInterface;
  17. /**
  18. * @category Zend
  19. * @package Zend_Mvc
  20. * @subpackage Service
  21. */
  22. class ModuleManagerFactory implements FactoryInterface
  23. {
  24. /**
  25. * Creates and returns the module manager
  26. *
  27. * Instantiates the default module listeners, providing them configuration
  28. * from the "module_listener_options" key of the ApplicationConfig
  29. * service. Also sets the default config glob path.
  30. *
  31. * Module manager is instantiated and provided with an EventManager, to which
  32. * the default listener aggregate is attached. The ModuleEvent is also created
  33. * and attached to the module manager.
  34. *
  35. * @param ServiceLocatorInterface $serviceLocator
  36. * @return ModuleManager
  37. */
  38. public function createService(ServiceLocatorInterface $serviceLocator)
  39. {
  40. if (!$serviceLocator->has('ServiceListener')) {
  41. $serviceLocator->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory');
  42. }
  43. $configuration = $serviceLocator->get('ApplicationConfig');
  44. $listenerOptions = new ListenerOptions($configuration['module_listener_options']);
  45. $defaultListeners = new DefaultListenerAggregate($listenerOptions);
  46. $serviceListener = $serviceLocator->get('ServiceListener');
  47. $serviceListener->addServiceManager(
  48. $serviceLocator,
  49. 'service_manager',
  50. 'Zend\ModuleManager\Feature\ServiceProviderInterface',
  51. 'getServiceConfig'
  52. );
  53. $serviceListener->addServiceManager(
  54. 'ControllerLoader',
  55. 'controllers',
  56. 'Zend\ModuleManager\Feature\ControllerProviderInterface',
  57. 'getControllerConfig'
  58. );
  59. $serviceListener->addServiceManager(
  60. 'ControllerPluginManager',
  61. 'controller_plugins',
  62. 'Zend\ModuleManager\Feature\ControllerPluginProviderInterface',
  63. 'getControllerPluginConfig'
  64. );
  65. $serviceListener->addServiceManager(
  66. 'ViewHelperManager',
  67. 'view_helpers',
  68. 'Zend\ModuleManager\Feature\ViewHelperProviderInterface',
  69. 'getViewHelperConfig'
  70. );
  71. $events = $serviceLocator->get('EventManager');
  72. $events->attach($defaultListeners);
  73. $events->attach($serviceListener);
  74. $moduleEvent = new ModuleEvent;
  75. $moduleEvent->setParam('ServiceManager', $serviceLocator);
  76. $moduleManager = new ModuleManager($configuration['modules'], $events);
  77. $moduleManager->setEvent($moduleEvent);
  78. return $moduleManager;
  79. }
  80. }