PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/aboozar/zf2
PHP | 102 lines | 61 code | 9 blank | 32 comment | 0 complexity | 04345d7d4ff0434e226637d29f403e73 MD5 | raw file
Possible License(s): BSD-3-Clause
  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\Listener\ServiceListener;
  14. use Zend\ModuleManager\ModuleEvent;
  15. use Zend\ModuleManager\ModuleManager;
  16. use Zend\ServiceManager\FactoryInterface;
  17. use Zend\ServiceManager\ServiceLocatorInterface;
  18. /**
  19. * @category Zend
  20. * @package Zend_Mvc
  21. * @subpackage Service
  22. */
  23. class ModuleManagerFactory implements FactoryInterface
  24. {
  25. /**
  26. * Default mvc-related service configuration -- can be overridden by modules.
  27. *
  28. * @var array
  29. */
  30. protected $defaultServiceConfiguration = array(
  31. 'invokables' => array(
  32. 'DispatchListener' => 'Zend\Mvc\DispatchListener',
  33. 'Request' => 'Zend\Http\PhpEnvironment\Request',
  34. 'Response' => 'Zend\Http\PhpEnvironment\Response',
  35. 'RouteListener' => 'Zend\Mvc\RouteListener',
  36. 'ViewManager' => 'Zend\Mvc\View\ViewManager',
  37. ),
  38. 'factories' => array(
  39. 'Application' => 'Zend\Mvc\Service\ApplicationFactory',
  40. 'Configuration' => 'Zend\Mvc\Service\ConfigurationFactory',
  41. 'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',
  42. 'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
  43. 'DependencyInjector' => 'Zend\Mvc\Service\DiFactory',
  44. 'Router' => 'Zend\Mvc\Service\RouterFactory',
  45. 'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory',
  46. 'ViewFeedRenderer' => 'Zend\Mvc\Service\ViewFeedRendererFactory',
  47. 'ViewFeedStrategy' => 'Zend\Mvc\Service\ViewFeedStrategyFactory',
  48. 'ViewJsonRenderer' => 'Zend\Mvc\Service\ViewJsonRendererFactory',
  49. 'ViewJsonStrategy' => 'Zend\Mvc\Service\ViewJsonStrategyFactory',
  50. ),
  51. 'aliases' => array(
  52. 'Config' => 'Configuration',
  53. 'ControllerPluginBroker' => 'ControllerPluginManager',
  54. 'Di' => 'DependencyInjector',
  55. 'Zend\Di\LocatorInterface' => 'DependencyInjector',
  56. 'Zend\Mvc\Controller\PluginBroker' => 'ControllerPluginBroker',
  57. 'Zend\Mvc\Controller\PluginManager' => 'ControllerPluginManager',
  58. ),
  59. );
  60. /**
  61. * Creates and returns the module manager
  62. *
  63. * Instantiates the default module listeners, providing them configuration
  64. * from the "module_listener_options" key of the ApplicationConfiguration
  65. * service. Also sets the default config glob path.
  66. *
  67. * Module manager is instantiated and provided with an EventManager, to which
  68. * the default listener aggregate is attached. The ModuleEvent is also created
  69. * and attached to the module manager.
  70. *
  71. * @param ServiceLocatorInterface $serviceLocator
  72. * @return ModuleManager
  73. */
  74. public function createService(ServiceLocatorInterface $serviceLocator)
  75. {
  76. $configuration = $serviceLocator->get('ApplicationConfiguration');
  77. $listenerOptions = new ListenerOptions($configuration['module_listener_options']);
  78. $defaultListeners = new DefaultListenerAggregate($listenerOptions);
  79. $serviceListener = new ServiceListener($serviceLocator, $this->defaultServiceConfiguration);
  80. $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\ModuleManager\Feature\ServiceProviderInterface', 'getServiceConfiguration');
  81. $serviceListener->addServiceManager('ControllerLoader', 'controllers', 'Zend\ModuleManager\Feature\ControllerProviderInterface', 'getControllerConfiguration');
  82. $serviceListener->addServiceManager('ControllerPluginManager', 'controller_plugins', 'Zend\ModuleManager\Feature\ControllerPluginProviderInterface', 'getControllerPluginConfiguration');
  83. $serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\ModuleManager\Feature\ViewHelperProviderInterface', 'getViewHelperConfiguration');
  84. $events = $serviceLocator->get('EventManager');
  85. $events->attach($defaultListeners);
  86. $events->attach($serviceListener);
  87. $moduleEvent = new ModuleEvent;
  88. $moduleEvent->setParam('ServiceManager', $serviceLocator);
  89. $moduleManager = new ModuleManager($configuration['modules'], $events);
  90. $moduleManager->setEvent($moduleEvent);
  91. return $moduleManager;
  92. }
  93. }