public function testDefaultListenerAggregateCanDetachItself()
 {
     $listenerAggregate = new DefaultListenerAggregate();
     $moduleManager = new ModuleManager(array('ListenerTestModule'));
     $this->assertEquals(1, count($moduleManager->getEventManager()->getEvents()));
     $listenerAggregate->attach($moduleManager->getEventManager());
     $this->assertEquals(3, count($moduleManager->getEventManager()->getEvents()));
     $listenerAggregate->detach($moduleManager->getEventManager());
     $this->assertEquals(1, count($moduleManager->getEventManager()->getEvents()));
 }
 /**
  * Attach one or more listeners
  *
  * @param EventCollection $events
  * @return DefaultListenerAggregate
  */
 public function attach(EventManagerInterface $events)
 {
     $options = $this->getOptions();
     $lazyLoading = $options->getLazyLoading();
     $listenerManager = new AuthManager($lazyLoading);
     $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE_AUTH, array($listenerManager, 'authorize'));
     return parent::attach($events);
 }
Example #3
0
 public function testCanNotLoadSomeObjectModuleWithoutIdentifier()
 {
     require_once __DIR__ . '/TestAsset/SomeModule/Module.php';
     $configListener = $this->defaultListeners->getConfigListener();
     $moduleManager = new ModuleManager(array(new \SomeModule\Module()), new EventManager());
     $moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
     $this->setExpectedException('Zend\\ModuleManager\\Exception\\RuntimeException');
     $moduleManager->loadModules();
 }
Example #4
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     $modulePaths = $this->getModulePathsForProject();
     // define module list
     if ($this->params->paramModuleList && count($this->params->paramModuleList) > 0) {
         // use modules parameter
         $moduleList = $this->params->paramModuleList;
     } else {
         $moduleList = $this->loadModulesForProject($modulePaths);
     }
     // init loadable modules
     $loadableModules = [];
     // loop through module list
     foreach ($moduleList as $moduleName) {
         foreach ($modulePaths as $modulePath) {
             // check module file
             $moduleFile = $modulePath . '/' . $moduleName . '/Module.php';
             if (file_exists($moduleFile)) {
                 $loadableModules[] = $moduleName;
             }
         }
     }
     // sort by key
     sort($loadableModules);
     // configure event managers
     $sharedEvents = new SharedEventManager();
     $eventManager = new EventManager($sharedEvents);
     // configure module manager
     $moduleManager = new ModuleManager($loadableModules, $eventManager);
     // configure defaukt listeners
     $defaultListeners = new DefaultListenerAggregate(new ListenerOptions(['module_paths' => $modulePaths]));
     $defaultListeners->attach($moduleManager->getEventManager());
     // load modules
     $moduleManager->loadModules();
     // set loaded modules
     $this->params->loadedModules = $moduleManager->getLoadedModules();
     // check loaded modules
     if (!empty($this->params->loadedModules)) {
         return 0;
     }
     // output fail message
     $this->console->writeTaskLine('task_fetch_load_modules_not_found', [$this->console->colorize($this->params->workingPath, Color::GREEN)]);
     return 1;
 }
 /**
  * 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');
     $listenerOptions = new ListenerOptions($configuration['module_listener_options']);
     $defaultListeners = new DefaultListenerAggregate($listenerOptions);
     $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;
 }