141 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			141 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace kernel\console\controllers;
 | |
| 
 | |
| use kernel\console\ConsoleController;
 | |
| use kernel\helpers\Debug;
 | |
| use kernel\helpers\Files;
 | |
| use kernel\helpers\Manifest;
 | |
| use kernel\models\Option;
 | |
| use ZipArchive;
 | |
| use kernel\services\ModuleService;
 | |
| 
 | |
| class ModuleController extends ConsoleController
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      * @throws \Exception
 | |
|      */
 | |
|     public function actionInstallModule(): void
 | |
|     {
 | |
|         if (!isset($this->argv['path'])) {
 | |
|             throw new \Exception('Missing module path "--path" specified');
 | |
|         }
 | |
| 
 | |
|         if (file_exists(ROOT_DIR . $this->argv['path'])) {
 | |
|             $moduleService = new ModuleService();
 | |
|             if ($moduleService->installModule($this->argv['path'])) {
 | |
|                 $this->out->r("Модуль установлен", 'green');
 | |
|             } else {
 | |
|                 $this->out->r("Ошибка установки модуля", 'red');
 | |
|             }
 | |
|         } else {
 | |
|             $this->out->r("Модуль не найден", 'red');
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws \Exception
 | |
|      */
 | |
|     public function actionUninstallModule(): void
 | |
|     {
 | |
|         if (!isset($this->argv['path'])) {
 | |
|             throw new \Exception('Missing module path "--path" specified');
 | |
|         }
 | |
| 
 | |
|         if (file_exists(ROOT_DIR . $this->argv['path'])) {
 | |
|             $moduleService = new ModuleService();
 | |
|             $moduleService->uninstallModule($this->argv['path']);
 | |
|             $this->out->r("Модуль удален", 'green');
 | |
|         } else {
 | |
|             $this->out->r("Модуль не найден", 'red');
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws \Exception
 | |
|      */
 | |
|     public function actionPackModule(): void
 | |
|     {
 | |
|         if (!isset($this->argv['path'])) {
 | |
|             throw new \Exception('Missing module path "--path" specified');
 | |
|         }
 | |
| 
 | |
|         if (file_exists(ROOT_DIR . $this->argv['path'])) {
 | |
|             $moduleService = new ModuleService();
 | |
|             $moduleService->packModule($this->argv['path']);
 | |
|             $this->out->r("Модуль заархивирован", 'green');
 | |
|         } else {
 | |
|             $this->out->r("Модуль не найден", 'red');
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws \Exception
 | |
|      */
 | |
|     public function actionUpdateModule(): void
 | |
|     {
 | |
|         if (!isset($this->argv['path'])) {
 | |
|             throw new \Exception('Missing module path "--path" specified');
 | |
|         }
 | |
|         if (file_exists(ROOT_DIR . $this->argv['path'])) {
 | |
|             $moduleService = new ModuleService();
 | |
|             if ($moduleService->updateModule($this->argv['path'])) {
 | |
|                 $this->out->r("Модуль обновлен", 'green');
 | |
|             } else {
 | |
|                 $this->out->r("Ошибка обновления модуля", 'red');
 | |
|             }
 | |
|         } else {
 | |
|             $this->out->r("Модуль не найден", 'red');
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function actionConstructModule(): void
 | |
|     {
 | |
|         $this->out->r("Введите slug модуля:", 'yellow');
 | |
|         $slug = substr(fgets(STDIN), 0, -1);
 | |
|         $slug = strtolower($slug);
 | |
| 
 | |
|         $this->out->r("Введите название модуля:", 'yellow');
 | |
|         $name = substr(fgets(STDIN), 0, -1);
 | |
| 
 | |
|         $this->out->r("Введите автора модуля:", 'yellow');
 | |
|         $author = substr(fgets(STDIN), 0, -1);
 | |
| 
 | |
|         $this->out->r("Введите название пунтка меню для модуля:", 'yellow');
 | |
|         $label = substr(fgets(STDIN), 0, -1);
 | |
| 
 | |
|         $moduleService = new ModuleService();
 | |
|         $moduleService->createDirs($slug);
 | |
| 
 | |
|         $moduleService->createManifest([
 | |
|             'name' => $name,
 | |
|             'author' => $author,
 | |
|             'slug' => $slug
 | |
|         ]);
 | |
|         $this->out->r("manifest.json создан", 'green');
 | |
| 
 | |
|         $moduleService->createControllers($slug);
 | |
|         $this->out->r("Контроллеры созданы", 'green');
 | |
| 
 | |
|         $moduleService->createRoutes($slug);
 | |
|         $this->out->r("Роуты созданы", 'green');
 | |
| 
 | |
|         $moduleService->createModuleClassFiles($slug, $label);
 | |
|         $this->out->r("Файлы модуля созданы", 'green');
 | |
| 
 | |
|         $moduleService->createModel($slug);
 | |
|         $this->out->r("Модель создана", 'green');
 | |
| 
 | |
|         $moduleService->createFormModel($slug);
 | |
|         $this->out->r("Форма валидации для модели создана", 'green');
 | |
| 
 | |
|         $moduleService->createService($slug);
 | |
|         $this->out->r("Сервис создан", 'green');
 | |
| 
 | |
|         $moduleService->createViews($slug);
 | |
|         $this->out->r("Представления созданы", 'green');
 | |
| 
 | |
|     }
 | |
| 
 | |
| } |