예제 #1
0
 public function loadActiveModules($isAdmin)
 {
     $moduleManager = $this->modularityService;
     $this->activeModules = $moduleManager->getActiveModules($isAdmin);
     //        \source\helpers\VarDumper::dump($this->activeModules);die;
     $module = $isAdmin ? "admin\\AdminModule" : "home\\HomeModule";
     foreach ($this->activeModules as $m) {
         $moduleId = $m['id'];
         $moduleDir = $m['dir'];
         $ModuleClassName = $m['dirClass'];
         $this->setModule($moduleId, ['class' => 'source\\modules\\' . $moduleDir . '\\' . $module]);
         $serviceFile = LsYii::getAlias('@source') . '\\modules\\' . $moduleDir . '\\' . $ModuleClassName . 'Service.php';
         if (FileHelper::exist($serviceFile)) {
             $serviceClass = 'source\\modules\\' . $moduleDir . '\\' . $ModuleClassName . 'Service';
             $serviceInstance = new $serviceClass();
             $this->set($serviceInstance->getServiceId(), $serviceInstance);
         }
     }
 }
예제 #2
0
 public function loadAllModules()
 {
     if ($this->allModules !== null) {
         return $this->allModules;
     }
     $this->allModules = [];
     $moduleRootPath = LsYii::getAlias('@source') . '/modules';
     if ($moduleRootDir = dir($moduleRootPath)) {
         while (($moduleFolder = $moduleRootDir->read()) !== false) {
             $currentModuleDir = $moduleRootPath . '/' . $moduleFolder;
             if (preg_match('|^\\.+$|', $moduleFolder) || !is_dir($currentModuleDir)) {
                 continue;
             }
             $moduleClassName = ucwords($moduleFolder);
             if (FileHelper::exist($currentModuleDir . '/' . $moduleClassName . 'Info.php')) {
                 $class = 'source\\modules\\' . $moduleFolder . '\\' . $moduleClassName . 'Info';
             } else {
                 continue;
             }
             $instance = null;
             try {
                 $instance = new $class();
                 if (empty($instance->id)) {
                     $instance->id = $moduleFolder;
                 }
                 if (empty($instance->name)) {
                     $instance->name = $moduleFolder;
                 }
             } catch (Exception $ex) {
                 $instance = null;
             }
             if ($instance !== null) {
                 $hasAdmin = FileHelper::exist($currentModuleDir . '/admin/AdminModule.php') ? true : false;
                 $hasHome = FileHelper::exist($currentModuleDir . '/home/HomeModule.php') ? true : false;
                 $this->allModules[$instance->id] = ['id' => $instance->id, 'dir' => $moduleFolder, 'dirClass' => $moduleClassName, 'class' => $class, 'instance' => $instance, 'canInstall' => true, 'canUninstall' => true, 'hasAdmin' => $hasAdmin, 'hasHome' => $hasHome, 'canActiveAdmin' => false, 'canActiveHome' => false];
             }
         }
     }
     return $this->allModules;
 }
예제 #3
0
 /**
  * 创建数据库
  * @param type $db
  * @param type $file
  */
 private function executeSql($db, $file)
 {
     $file = LsYii::getAlias("@data/sql/{$file}.sql");
     if (!FileHelper::exist($file)) {
         self::_appendLog(LsYii::gT("安装的sql文件不存在"), true);
         return false;
     }
     $tbPre = $db->tablePrefix;
     //获取sql文件
     $content = file_get_contents($file);
     $sqls = self::_splitsql($content);
     if (is_array($sqls)) {
         foreach ($sqls as $sql) {
             if (trim($sql) != '') {
                 $db->createCommand(str_replace('#@__', $tbPre, $sql))->execute();
                 $msgLog = self::_createMsgLog(str_replace('#@__', $tbPre, $sql));
                 self::_appendLog($msgLog);
             }
         }
     } else {
         $db->createCommand(str_replace('#@__', $tbPre, $sqls))->execute();
         $msgLog = self::_createMsgLog(str_replace('#@__', $tbPre, $sqls));
         self::_appendLog($msgLog);
     }
     return true;
 }