| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | 
							- <?php
 
- namespace common\components;
 
- use common\models\Module;
 
- use Yii;
 
- use yii\base\BootstrapInterface;
 
- use yii\base\Component;
 
- use yii\helpers\ArrayHelper;
 
- class LoadModule extends Component implements BootstrapInterface
 
- {
 
-     public function bootstrap($app)
 
-     {
 
-         
 
-         if (!file_exists(Yii::getAlias('@root/web/storage/install.txt'))) {
 
-             return;
 
-         }
 
-         $models = Module::findOpenModules(Module::TYPE_CORE);
 
-         $bootstrapType = $app->id;
 
-         foreach ($models as $model) {
 
-             $modulePackage = Yii::$app->moduleManager->findOne($model->id);
 
-             if ($modulePackage === null) {
 
-                 continue;
 
-             }
 
-             $class = [
 
-                 'class' => $modulePackage->getModuleClass(),
 
-                 'params' => $modulePackage->getConfig()
 
-             ];
 
-             $this->setModule($model->id, $class);
 
-             if ($model->bootstrap == '*') {
 
-                 $bootstraps = ['frontend', 'backend', 'api', 'wechat', 'console'];
 
-             } else {
 
-                 $bootstraps = explode("|", $model->bootstrap);
 
-             }
 
-             if (in_array($bootstrapType, $bootstraps)) {
 
-                 $module = \Yii::$app->getModule($model->id);
 
-                 if ($module instanceof BootstrapInterface) {
 
-                     $module->bootstrap($app);
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     public function setModule($id, $config)
 
-     {
 
-         $definitions = \Yii::$app->getModules();
 
-         Yii::$app->setModule($id,
 
-             ArrayHelper::merge($config, array_key_exists($id, $definitions) ? $definitions[$id] : [])
 
-         );
 
-     }
 
- }
 
 
  |