function loadModule($module)
    {
        $moduleNameStr = $module;

        if(is_array($module)) {
            # # names can be pass as array ['mod_name' => $options]
            # ['module_name' => 'resolver\to\module' or Object or ...]
            if (empty($module)
                || array_values($module) === $module # must be associate array
                || count($module) > 1                # just module name in key=>options
            )
                throw new \Exception('Module in form of array can be ["moduleName" => X],
                X can be either Module Class Map or Module Object Instance');

            $moduleNameStr = key($module);
        }

        if ($this->hasLoaded($moduleNameStr))
            // Module is loaded before
            return $this;

        
        // ...

        # Resolve to module instance:
        
        $collectorPass = new DataCollectorModuleManager;
        $collectorPass->setModule($module);
        $collectorPass->setModuleManager($this);

        $resolvedModule = $this->event()->trigger(EventHeapOfModuleManager::EVENT_RESOLVE_TO_MODULE
            , $collectorPass
            , new MeeterCallable(function($result, MeeterCallable $self) 
            {
                /** @var EventHeapOfModuleManager $event */
                $event = $self->event();
                $resolvedModule = $result;
                if ($resolvedModule) {
                    $event->collector()->setModuleResolved($resolvedModule);
                    $event->stopPropagation();
                }
                
                return $resolvedModule;
            })
        )->trigger(ModuleManager\EventHeapOfModuleManager::EVENT_INITIALIZE_MODULE)
         ->then(function(DataCollectorModuleManager $result){
             return $result->getModuleResolved();
         });


        // Collector attr. "module_resolved" may set to false (logically) during event!
        (! $resolvedModule ) ?: $this->_c__loadedModules[$moduleNameStr] = $resolvedModule;
        return $this;
    }
function loadModule($module)
    {
        $moduleNameStr = $module;

        if(is_array($module)) {
            # # names can be pass as array ['mod_name' => $options]
            # ['module_name' => 'resolver\to\module' or Object or ...]
            if (empty($module)
                || array_values($module) === $module # must be associate array
                || count($module) > 1                # just module name in key=>options
            )
                throw new \Exception('Module in form of array can be ["moduleName" => X],
                X can be either Module Class Map or Module Object Instance');

            $moduleNameStr = key($module);
        }

        if ($this->hasLoaded($moduleNameStr))
            // Module is loaded before
            return $this;

        
        // ...

        # Resolve to module instance:
        
        $collectorPass = new DataCollectorModuleManager;
        $collectorPass->setModule($module);
        $collectorPass->setModuleManager($this);

        $resolvedModule = $this->event()->trigger(EventHeapOfModuleManager::EVENT_RESOLVE_TO_MODULE
            , $collectorPass
            , new MeeterCallable(function($result, MeeterCallable $self) 
            {
                /** @var EventHeapOfModuleManager $event */
                $event = $self->event();
                $resolvedModule = $result;
                if ($resolvedModule) {
                    $event->collector()->setModuleResolved($resolvedModule);
                    $event->stopPropagation();
                }
                
                return $resolvedModule;
            })
        )->trigger(ModuleManager\EventHeapOfModuleManager::EVENT_INITIALIZE_MODULE)
         ->then(function(DataCollectorModuleManager $result){
             return $result->getModuleResolved();
         });


        // Collector attr. "module_resolved" may set to false (logically) during event!
        (! $resolvedModule ) ?: $this->_c__loadedModules[$moduleNameStr] = $resolvedModule;
        return $this;
    }
function loadModule ( $ module ) { $ moduleNameStr = $ module ; if ( is_array ( $ module ) ) { # # names can be pass as array ['mod_name' => $options] # ['module_name' => 'resolver\to\module' or Object or ...] if ( empty ( $ module ) || array_values ( $ module ) === $ module # must be associate array || count ( $ module ) > 1 # just module name in key=>options ) throw new \ Exception ( 'Module in form of array can be ["moduleName" => X],
                X can be either Module Class Map or Module Object Instance' ) ; $ moduleNameStr = key ( $ module ) ; } if ( $ this -> hasLoaded ( $ moduleNameStr ) ) // Module is loaded before return $ this ; // ... # Resolve to module instance: $ collectorPass = new DataCollectorModuleManager ; $ collectorPass -> setModule ( $ module ) ; $ collectorPass -> setModuleManager ( $ this ) ; $ resolvedModule = $ this -> event ( ) -> trigger ( EventHeapOfModuleManager :: EVENT_RESOLVE_TO_MODULE , $ collectorPass , new MeeterCallable ( function ( $ result , MeeterCallable $ self ) { /** @var EventHeapOfModuleManager $event */ $ event = $ self -> event ( ) ; $ resolvedModule = $ result ; if ( $ resolvedModule ) { $ event -> collector ( ) -> setModuleResolved ( $ resolvedModule ) ; $ event -> stopPropagation ( ) ; } return $ resolvedModule ; } ) ) -> trigger ( ModuleManager \ EventHeapOfModuleManager :: EVENT_INITIALIZE_MODULE ) -> then ( function ( DataCollectorModuleManager $ result ) { return $ result -> getModuleResolved ( ) ; } ) ; // Collector attr. "module_resolved" may set to false (logically) during event! ( ! $ resolvedModule ) ? : $ this -> _c__loadedModules [ $ moduleNameStr ] = $ resolvedModule ; return $ this ; }
Get Module Instance By Name

- attain module object by name
- initialize module
- register module as loaded modules

! don`t reload modules on each call request

loadModule('module_name')
loadModule(['module_name' => 'resolver\to\module' or Object or ...])

@param string|array $module

@throws exModuleNotFound
@throws \Exception
@return $this
Get Module Instance By Name