Example #1
0
 /**
  * Merge the config for each module
  *
  * @param ModuleEvent $e
  * @return ConfigListener
  */
 public function onLoadModule(ModuleEvent $e)
 {
     $module = $e->getModule();
     if (!$module instanceof ConfigProviderInterface && !is_callable(array($module, 'getConfig'))) {
         return $this;
     }
     $config = $module->getConfig();
     $this->addConfig($e->getModuleName(), $config);
     return $this;
 }
Example #2
0
 /**
  * Use merged configuration to configure service manager
  *
  * If the merged configuration has a non-empty, array 'container'
  * key, it will be passed to a ServiceManager Config object, and
  * used to configure the service manager.
  *
  * @param ModuleEvent $e
  * @throws Exception\RuntimeException
  * @return void
  */
 public function onLoadModulesPost(ModuleEvent $e)
 {
     $moduleConfig = $e->getModuleConfig();
     $config = $moduleConfig->getMergedConfig(false);
     foreach ($this->containers as $key => $sm) {
         if (isset($config[$sm['config_key']]) && is_array($config[$sm['config_key']]) && !empty($config[$sm['config_key']])) {
             $this->containers[$key]['configuration']['merged_config'] = $config[$sm['config_key']];
         }
         // Merge all of the things!
         $smConfig = array();
         foreach ($this->containers[$key]['configuration'] as $configs) {
             if (isset($configs['configuration_classes'])) {
                 foreach ($configs['configuration_classes'] as $class) {
                     $configs = ArrayHelper::merge($configs, $this->serviceConfigToArray($class));
                 }
             }
             $smConfig = ArrayHelper::merge($smConfig, $configs);
         }
         if (!$sm['container'] instanceof Container) {
             $instance = $this->defaultServiceManager->get($sm['container']);
             if (!$instance instanceof Container) {
                 throw new ErrorException(sprintf('Could not find a valid ServiceManager for %s', $sm['container']));
             }
             $sm['container'] = $instance;
         }
         $this->configureContainer($sm['container'], $smConfig);
     }
 }
Example #3
0
 /**
  * 向app注册引导事件,在请求前,由于默认模块和组件可能会重名所以定义这个事件
  * @param ModuleEvent $e
  */
 public function onBootstrap(ModuleEvent $e)
 {
     $module = $e->getModule();
     if (!$module instanceof BootstrapListenerInterface && !method_exists($module, 'onBootstrap')) {
         return;
     }
     $moduleManager = $e->getTarget();
     Event::on($this->appClass, $this->appBootstarpEventName, array($module, 'onBootstrap'));
 }
Example #4
0
 /**
  * Set the module event
  *
  * @param ModuleEvent $event
  * @return ModuleManager
  */
 public function setEvent(ModuleEvent $event)
 {
     if (!$event->getModuleConfig()) {
         $event->setModuleConfig($this->getConfig());
     }
     $this->event = $event;
     return $this;
 }