service = $service; } public function behaviors(): array { return [ 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'actions' => ['list', 'disable', 'enable', 'delete', 'search'], 'allow' => true, 'roles' => ['ModuleManagement'], ], [ // all the action are accessible to admin 'allow' => true, 'roles' => ['admin'], ], ], ], 'verbs' => [ 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], 'disable' => ['POST'], 'enable' => ['POST'], 'install' => ['POST'], ], ], ]; } /** * List of modules * @return string */ public function actionList(): string { $modules = Yii::$app->moduleManager->getModules(); return $this->render('list', [ 'modules' => $modules, ]); } /** * @param $id * @return Response * @throws NotFoundHttpException * @throws ErrorException * @throws Exception */ public function actionDelete($id): Response { $module = $this->findModel($id); $this->service->delete($module); return $this->redirect(['module/list']); } /** * @param $id * @return Response * @throws NotFoundHttpException */ public function actionDisable($id): Response { $module = $this->findModel($id); $this->service->disable($module); return $this->redirect(['module/list']); } /** * @param $id * @return Response * @throws NotFoundHttpException */ public function actionEnable($id): Response { $module = $this->findModel($id); $this->service->enable($module); return $this->redirect(['module/list']); } public function actionSearch(): string { $message = null; try { $list = file_get_contents('http://zertex.ru/zxcms/modules.txt'); $links = array_filter(explode('|', $list)); $modules = []; foreach ($links as $link) { $manifest = file_get_contents($link); $manifest = eval(str_replace('language . '/' . $manifest['name'] . '.php', $link); try { $language = file_get_contents($languageFile); $language = eval(str_replace('render('remote-list', [ 'modules' => $modules, 'message' => $message, ]); } /** * @param $id * @return ModuleRecord * @throws NotFoundHttpException */ protected function findModel($id): ModuleRecord { if (($model = ModuleRecord::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested module does not exist.'); } }