Compare commits

..

3 Commits

Author SHA1 Message Date
4ff9fa9ad3 kernel update 2024-12-18 12:46:57 +03:00
653e0bc983 Merge branch 'master' of https://git.itguild.info/ItGuild/igfs 2024-12-16 14:38:13 +03:00
9fa3daf767 test delete 2024-12-16 14:37:11 +03:00
57 changed files with 1023 additions and 88 deletions

View File

@ -5,7 +5,6 @@ DB_USER={db_user}
DB_DRIVER=mysql DB_DRIVER=mysql
DB_PASSWORD={db_password} DB_PASSWORD={db_password}
DB_NAME={db_name} DB_NAME={db_name}
DB_CHARSET=utf8mb4 DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX='' DB_PREFIX=''

View File

@ -30,8 +30,13 @@ class ModuleShopModule extends Module
]); ]);
} }
/**
* @throws \Exception
*/
public function deactivate(): void public function deactivate(): void
{ {
$this->menuService->removeItemBySlug("module_shop"); $this->menuService->removeItemBySlug("module_shop");
$this->migrationService->rollbackAtPath("{APP}/modules/module_shop/migrations");
} }
} }

View File

@ -0,0 +1,84 @@
<?php
namespace app\modules\module_shop\controllers;
use app\modules\module_shop\models\forms\CreateModuleShopForm;
use app\modules\module_shop\models\ModuleShop;
use app\modules\module_shop\services\ModuleShopService;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\FileUpload;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\services\ModuleService;
use ZipArchive;
class KernelShopController extends AdminController
{
protected ModuleShopService $moduleShopService;
protected Files $files;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = APP_DIR . "/modules/module_shop/views/kernel/";
$this->moduleShopService = new ModuleShopService();
$this->files = new Files();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
/**
* @throws \Exception
*/
#[NoReturn] public function actionAdd(): void
{
$moduleShopForm = new CreateModuleShopForm();
$moduleShopForm->load($_REQUEST);
if (isset($_FILES['path_to_archive']) && $_FILES['path_to_archive']['error'] === UPLOAD_ERR_OK) {
$file = new FileUpload($_FILES['path_to_archive'], ['zip', 'rar', 'igk']);
$file->upload();
$moduleShopForm->setItem('path_to_archive', $file->getUploadFile());
}
$tmpKernelDir = md5(time());
$zip = new ZipArchive;
$res = $zip->open(ROOT_DIR . $moduleShopForm->getItem('path_to_archive'));
if ($res === TRUE) {
if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
mkdir(RESOURCES_DIR . '/tmp/ms/');
}
$tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpKernelDir . "/";
$zip->extractTo($tmpModuleShopDirFull);
$zip->close();
if (file_exists($tmpModuleShopDirFull . "kernel/manifest.json")){
$kernelInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "kernel");
$moduleShopForm->load($kernelInfo);
}
else {
throw new \Exception("Manifest.json file not found");
}
$this->files->recursiveRemoveDir($tmpModuleShopDirFull);
}
else {
throw new \Exception("zip not found");
}
if ($moduleShopForm->validate()) {
$kernel = $this->moduleShopService->create($moduleShopForm);
if ($kernel) {
Flash::setMessage("success", "Ядро добавлено.");
$this->redirect("/admin/module_shop/view/" . $kernel->id);
}
}
Flash::setMessage("error", "Ошибка добавления ядра: <br>" . $moduleShopForm->getErrorsStr());
$this->redirect("/admin/module_shop/kernel/create");
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\modules\module_shop\controllers;
use app\modules\module_shop\models\ModuleShop;
use JetBrains\PhpStorm\NoReturn;
use kernel\helpers\Debug;
use kernel\Request;
use kernel\RestController;
class KernelShopRestController extends RestController
{
public function __construct()
{
$this->model = new ModuleShop();
}
#[NoReturn] public function actionUpdate($id): void
{
$model = $this->model->where("id", $id)->first();
$model->installations++;
$model->save();
$this->renderApi($model->toArray());
}
}

View File

@ -11,18 +11,21 @@ use kernel\app_modules\tag\services\TagService;
use kernel\FileUpload; use kernel\FileUpload;
use kernel\Flash; use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\services\ModuleService; use kernel\services\ModuleService;
use ZipArchive; use ZipArchive;
class ModuleShopController extends AdminController class ModuleShopController extends AdminController
{ {
protected ModuleShopService $moduleShopService; protected ModuleShopService $moduleShopService;
protected Files $files;
protected function init(): void protected function init(): void
{ {
parent::init(); parent::init();
$this->cgView->viewPath = APP_DIR . "/modules/module_shop/views/"; $this->cgView->viewPath = APP_DIR . "/modules/module_shop/views/";
$this->moduleShopService = new ModuleShopService(); $this->moduleShopService = new ModuleShopService();
$this->files = new Files();
} }
public function actionCreate(): void public function actionCreate(): void
@ -44,14 +47,14 @@ class ModuleShopController extends AdminController
$moduleShopForm->setItem('path_to_archive', $file->getUploadFile()); $moduleShopForm->setItem('path_to_archive', $file->getUploadFile());
} }
$tmpThemeDir = md5(time()); $tmpModuleDir = md5(time());
$zip = new ZipArchive; $zip = new ZipArchive;
$res = $zip->open(ROOT_DIR . $moduleShopForm->getItem('path_to_archive')); $res = $zip->open(ROOT_DIR . $moduleShopForm->getItem('path_to_archive'));
if ($res === TRUE) { if ($res === TRUE) {
if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) { if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
mkdir(RESOURCES_DIR . '/tmp/ms/'); mkdir(RESOURCES_DIR . '/tmp/ms/');
} }
$tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpThemeDir . "/"; $tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpModuleDir . "/";
$zip->extractTo($tmpModuleShopDirFull); $zip->extractTo($tmpModuleShopDirFull);
$zip->close(); $zip->close();
@ -62,6 +65,8 @@ class ModuleShopController extends AdminController
else { else {
throw new \Exception("Manifest.json file not found"); throw new \Exception("Manifest.json file not found");
} }
$this->files->recursiveRemoveDir($tmpModuleShopDirFull);
} }
else { else {
throw new \Exception("zip not found"); throw new \Exception("zip not found");
@ -71,11 +76,11 @@ class ModuleShopController extends AdminController
$module = $this->moduleShopService->create($moduleShopForm); $module = $this->moduleShopService->create($moduleShopForm);
if ($module) { if ($module) {
Flash::setMessage("success", "Модуль " . $moduleShopForm->getItem("name") . " добавлен."); Flash::setMessage("success", "Модуль " . $moduleShopForm->getItem("name") . " добавлен.");
$this->redirect("/admin/module_shop/" . $module->id); $this->redirect("/admin/module_shop/view/" . $module->id);
} }
} }
Flash::setMessage("error", "Ошибка добавления модуля: <br>" . $moduleShopForm->getErrorsStr()); Flash::setMessage("error", "Ошибка добавления модуля: <br>" . $moduleShopForm->getErrorsStr());
$this->redirect("/admin/module_shop/create"); $this->redirect("/admin/module_shop/module/create");
} }
public function actionIndex(int $page_number = 1): void public function actionIndex(int $page_number = 1): void
@ -101,6 +106,9 @@ class ModuleShopController extends AdminController
throw new \Exception("The module not found"); throw new \Exception("The module not found");
} }
$name = $module->name; $name = $module->name;
$dir = $module->path_to_archive;
$this->files->recursiveRemoveDir(ROOT_DIR . dirname($dir, 2));
$module->delete(); $module->delete();
Flash::setMessage("success", "Модуль " . $name . " удален."); Flash::setMessage("success", "Модуль " . $name . " удален.");

View File

@ -97,7 +97,7 @@ class ModuleShopRestController extends RestController
$this->renderApi($res); $this->renderApi($res);
} }
public function actionInstall($id): void #[NoReturn] public function actionInstall($id): void
{ {
$model = $this->model->where("id", $id)->first(); $model = $this->model->where("id", $id)->first();
$model->installations++; $model->installations++;

View File

@ -14,6 +14,7 @@ return new class extends Migration {
$table->increments('id'); $table->increments('id');
$table->string("name", 255)->nullable(false); $table->string("name", 255)->nullable(false);
$table->string("slug", 255)->nullable(false); $table->string("slug", 255)->nullable(false);
$table->string("type", 255)->nullable(false);
$table->text("description")->nullable(false); $table->text("description")->nullable(false);
$table->string("version", 255)->nullable(false); $table->string("version", 255)->nullable(false);
$table->string("author", 255)->nullable(false); $table->string("author", 255)->nullable(false);

View File

@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id * @property int $id
* @property string $name * @property string $name
* @property string $slug * @property string $slug
* @property string $type
* @property string $version * @property string $version
* @property string $description * @property string $description
* @property string $author * @property string $author
@ -24,7 +25,7 @@ class ModuleShop extends Model
protected $table = "module_shop"; protected $table = "module_shop";
protected $fillable = ['name', 'slug', 'version', 'description', 'author', 'status', 'dependence', 'installations', 'views']; protected $fillable = ['name', 'slug', 'type', 'version', 'description', 'author', 'status', 'dependence', 'installations', 'views'];
public static function labels(): array public static function labels(): array
{ {
@ -35,6 +36,7 @@ class ModuleShop extends Model
'author' => 'Автор', 'author' => 'Автор',
'status' => 'Статус', 'status' => 'Статус',
'slug' => 'Slug', 'slug' => 'Slug',
'type' => 'Тип',
'dependence' => 'Зависимости', 'dependence' => 'Зависимости',
'installations' => 'Установки', 'installations' => 'Установки',
'views' => 'Просмотры', 'views' => 'Просмотры',

View File

@ -8,14 +8,26 @@ class CreateModuleShopForm extends FormModel
{ {
public function rules(): array public function rules(): array
{ {
// return [
// 'name' => 'required|min-str-len:3',
// 'version' => 'required',
// 'description' => 'required|min-str-len:10',
// 'author' => 'required',
// 'status' => 'required',
// 'slug' => 'required',
// 'type' => 'required',
// 'path_to_archive' => 'required',
// 'dependence' => '',
// ];
return [ return [
'name' => 'required|min-str-len:3', 'name' => '',
'version' => 'required', 'version' => '',
'description' => 'required|min-str-len:10', 'description' => '',
'author' => 'required', 'author' => '',
'status' => 'required', 'status' => '',
'slug' => 'required', 'slug' => '',
'path_to_archive' => 'required', 'type' => '',
'path_to_archive' => '',
'dependence' => '', 'dependence' => '',
]; ];
} }

View File

@ -9,13 +9,20 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
App::$collector->group(["prefix" => "module_shop"], function (CgRouteCollector $router) { App::$collector->group(["prefix" => "module_shop"], function (CgRouteCollector $router) {
App::$collector->get('/', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionIndex']); App::$collector->get('/', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionIndex']); App::$collector->get('/page/{page_number}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionCreate']); App::$collector->get('/view/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionView']);
App::$collector->post("/", [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionAdd']);
App::$collector->get('/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionUpdate']); App::$collector->any('/update/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionEdit']); App::$collector->any("/edit/{id}", [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionDelete']); App::$collector->get('/delete/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionDelete']);
App::$collector->get('/pack/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionPack']); App::$collector->get('/pack/{id}', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionPack']);
App::$collector->group(["prefix" => "module"], function (CgRouteCollector $router) {
App::$collector->get('/create', [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\module_shop\controllers\ModuleShopController::class, 'actionAdd']);
});
App::$collector->group(["prefix" => "kernel"], function (CgRouteCollector $router) {
App::$collector->get('/create', [\app\modules\module_shop\controllers\KernelShopController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\module_shop\controllers\KernelShopController::class, 'actionAdd']);
});
}); });
}); });
@ -24,6 +31,9 @@ App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
App::$collector->group(["prefix" => "module_shop"], function (CgRouteCollector $router) { App::$collector->group(["prefix" => "module_shop"], function (CgRouteCollector $router) {
App::$collector->get('/gb_slug', [\app\modules\module_shop\controllers\ModuleShopRestController::class, 'actionIndexGroupBySlug']); App::$collector->get('/gb_slug', [\app\modules\module_shop\controllers\ModuleShopRestController::class, 'actionIndexGroupBySlug']);
App::$collector->get('/install/{id}', [\app\modules\module_shop\controllers\ModuleShopRestController::class, 'actionInstall']); App::$collector->get('/install/{id}', [\app\modules\module_shop\controllers\ModuleShopRestController::class, 'actionInstall']);
App::$collector->group(["prefix" => "kernel"], function (CgRouteCollector $router) {
App::$collector->get('/update/{id}', [\app\modules\module_shop\controllers\KernelShopRestController::class, 'actionUpdate']);
});
}); });
$router->rest("module_shop", [\app\modules\module_shop\controllers\ModuleShopRestController::class]); $router->rest("module_shop", [\app\modules\module_shop\controllers\ModuleShopRestController::class]);
}); });

View File

@ -23,6 +23,7 @@ class ModuleShopService extends ModuleService
$model->path_to_archive = $form_model->getItem("path_to_archive"); $model->path_to_archive = $form_model->getItem("path_to_archive");
$model->dependence = $form_model->getItem("dependence"); $model->dependence = $form_model->getItem("dependence");
$model->slug = $form_model->getItem("slug"); $model->slug = $form_model->getItem("slug");
$model->type = $form_model->getItem("type");
if ($model->save()) { if ($model->save()) {
return $model; return $model;
@ -41,6 +42,7 @@ class ModuleShopService extends ModuleService
$model->path_to_archive = $form_model->getItem("path_to_archive"); $model->path_to_archive = $form_model->getItem("path_to_archive");
$model->dependence = $form_model->getItem("dependence"); $model->dependence = $form_model->getItem("dependence");
$model->slug = $form_model->getItem("slug"); $model->slug = $form_model->getItem("slug");
$model->type = $form_model->getItem("type");
if ($model->save()) { if ($model->save()) {
return $model; return $model;

View File

@ -6,7 +6,7 @@
use app\modules\module_shop\models\ModuleShop; use app\modules\module_shop\models\ModuleShop;
$form = new \itguild\forms\ActiveForm(); $form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/module_shop", enctype: 'multipart/form-data'); $form->beginForm("/admin/module_shop/module", enctype: 'multipart/form-data');

View File

@ -24,8 +24,9 @@ $table->columns([
} }
]); ]);
$table->beforePrint(function () { $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/module_shop/create")->fetch(); $btn = PrimaryBtn::create("Добавить модуль", "/admin/module_shop/module/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); $btn .= PrimaryBtn::create("Добавить ядро", "/admin/module_shop/kernel/create")->fetch();
return $btn;
}); });
$table->addAction(ViewActionColumn::class); $table->addAction(ViewActionColumn::class);
$table->addAction(DeleteActionColumn::class); $table->addAction(DeleteActionColumn::class);

View File

@ -0,0 +1,53 @@
<?php
/**
* @var ModuleShop $model
*/
use app\modules\module_shop\models\ModuleShop;
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/module_shop/kernel", enctype: 'multipart/form-data');
$form->field(class: \itguild\forms\inputs\File::class, name: "path_to_archive", params: [
'class' => "form-control",
'placeholder' => 'Путь к файлу модуля',
'value' => $model->path_to_archive ?? ''
])
->setLabel("Путь к файлу модуля")
->render();
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
'class' => "form-control",
'value' => $model->status ?? ''
])
->setLabel("Статус")
->setOptions(ModuleShop::getStatus())
->render();
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
'class' => "btn btn-warning",
'value' => 'Сбросить',
'typeInput' => 'reset'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -13,7 +13,7 @@ const KERNEL_MODULES_DIR = __DIR__ . "/kernel/modules";
const KERNEL_ADMIN_THEMES_DIR = __DIR__ . "/kernel/admin_themes"; const KERNEL_ADMIN_THEMES_DIR = __DIR__ . "/kernel/admin_themes";
const CONSOLE_DIR = __DIR__ . "/kernel/console"; const CONSOLE_DIR = __DIR__ . "/kernel/console";
const RESOURCES_DIR = __DIR__ . "/resources"; const RESOURCES_DIR = __DIR__ . "/resources";
const KERNEL_TEMPLATES_DIR = __DIR__ . "/kernel/templates";
const KERNEL_APP_MODULES_DIR = KERNEL_DIR . "/app_modules"; const KERNEL_APP_MODULES_DIR = KERNEL_DIR . "/app_modules";
const APP_DIR = ROOT_DIR . "/app"; const APP_DIR = ROOT_DIR . "/app";
@ -29,6 +29,7 @@ function getConst($text): array|false|string
"{KERNEL}" => KERNEL_DIR, "{KERNEL}" => KERNEL_DIR,
"{KERNEL_MODULES}" => KERNEL_MODULES_DIR, "{KERNEL_MODULES}" => KERNEL_MODULES_DIR,
"{KERNEL_APP_MODULES}" => KERNEL_APP_MODULES_DIR, "{KERNEL_APP_MODULES}" => KERNEL_APP_MODULES_DIR,
"{KERNEL_TEMPLATES}" => KERNEL_TEMPLATES_DIR,
"{CONSOLE}" => CONSOLE_DIR, "{CONSOLE}" => CONSOLE_DIR,
"{APP}" => APP_DIR, "{APP}" => APP_DIR,
]; ];

View File

@ -2,7 +2,7 @@
$secure_config = [ $secure_config = [
'web_auth_type' => 'email_code', // login_password, email_code 'web_auth_type' => 'email_code', // login_password, email_code
'token_type' => 'crypt', // random_bytes, md5, crypt, hash, JWT 'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT
'token_expired_time' => "+30 days", // +1 day 'token_expired_time' => "+30 days", // +1 day
]; ];

View File

@ -19,7 +19,9 @@
"firebase/php-jwt": "^6.10", "firebase/php-jwt": "^6.10",
"k-adam/env-editor": "^2.0", "k-adam/env-editor": "^2.0",
"guzzlehttp/guzzle": "^7.9", "guzzlehttp/guzzle": "^7.9",
"phpmailer/phpmailer": "^6.9" "phpmailer/phpmailer": "^6.9",
"zircote/swagger-php": "^4.11",
"doctrine/annotations": "^2.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -46,8 +46,16 @@ class CgRouteCollector extends RouteCollector
//TODO //TODO
} }
public function console($route, $handler, array $filters = []): void /**
* @param $route
* @param $handler
* @param array $filters
* @param array $additionalInfo
* @return void
*/
public function console($route, $handler, array $filters = [], array $additionalInfo = []): void
{ {
$this->addRoute(Route::GET, $route, $handler, $filters); $additionalInfo['type'] = "console";
$this->addRoute(Route::GET, $route, $handler, $filters, $additionalInfo);
} }
} }

View File

@ -10,6 +10,8 @@ class CgView
public array $varToLayout = []; public array $varToLayout = [];
public bool|string $layout = false; public bool|string $layout = false;
protected array $metaArr = [];
public function __construct() public function __construct()
{ {
@ -34,14 +36,37 @@ class CgView
$this->varToLayout[$key] = $value; $this->varToLayout[$key] = $value;
} }
private function createContent(string $view, array $data = []): false|string public function setTitle(string $title): void
{
$this->addVarToLayout('title', $title);
}
public function setMeta(array $meta): void
{
foreach ($meta as $key => $value){
$this->metaArr[$key] = $value;
}
}
public function getMeta(): string
{
$meta = "";
foreach ($this->metaArr as $key => $value){
$meta .= "<meta name='$key' content='$value'>";
}
return $meta;
}
private function createContent(string $viewFile, array $data = []): false|string
{ {
ob_start(); ob_start();
$view = $this;
foreach ($data as $key => $datum) { foreach ($data as $key => $datum) {
${"$key"} = $datum; ${"$key"} = $datum;
} }
include($this->viewPath . $view); include($this->viewPath . $viewFile);
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
@ -50,6 +75,10 @@ class CgView
$file_content = $content; $file_content = $content;
if (!isset($title)){
$title = "No Title";
}
$layoutPath = $this->viewPath; $layoutPath = $this->viewPath;
if ($this->layout) { if ($this->layout) {

View File

@ -2,15 +2,18 @@
/** /**
* @var $content * @var $content
* @var string $resources * @var string $resources
* @var string $title
* @var \kernel\CgView $view
*/ */
\Josantonius\Session\Facades\Session::start(); \Josantonius\Session\Facades\Session::start();
?> ?>
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<title>Sidebar 01</title> <title><?= $title ?></title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?= $view->getMeta() ?>
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">

View File

@ -4,6 +4,8 @@
namespace kernel\console; namespace kernel\console;
use kernel\helpers\Debug;
class Out class Out
{ {
private $foreground_colors = array(); private $foreground_colors = array();
@ -64,6 +66,11 @@ class Out
echo $this->get($string, $foreground_color, $background_color) . "\n"; echo $this->get($string, $foreground_color, $background_color) . "\n";
} }
public function inLine($string, $foreground_color = null, $background_color = null): void
{
echo $this->get($string, $foreground_color, $background_color) ;
}
// Returns all foreground color names // Returns all foreground color names
public function getForegroundColors() public function getForegroundColors()
{ {
@ -75,4 +82,16 @@ class Out
{ {
return array_keys($this->background_colors); return array_keys($this->background_colors);
} }
// public function printHeaderTable(): void
// {
// echo "\n+-----------------------------+-----------------------------+-----------------------------+-----------------------------+\n";
// printf("%-30s", "| Routs");
// printf("%-30s", "| Description");
// printf("%-30s", "| Params");
// printf("%-30s", "| Params description");
// printf("%-30s", "|");
// echo "\n+-----------------------------+-----------------------------+-----------------------------+-----------------------------+\n";
// }
} }

View File

@ -27,7 +27,7 @@ class KernelController extends ConsoleController
if (file_exists(ROOT_DIR . $this->argv['path'])) { if (file_exists(ROOT_DIR . $this->argv['path'])) {
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel'; $tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel';
$this->files->copy_folder(KERNEL_DIR, $tmpKernelDirFull); $this->files->copy_folder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull);
$this->out->r("Ядро скопировано во временную папку", 'green'); $this->out->r("Ядро скопировано во временную папку", 'green');
} else { } else {
$this->out->r("Ядро не найдено", 'red'); $this->out->r("Ядро не найдено", 'red');
@ -65,11 +65,19 @@ class KernelController extends ConsoleController
$this->out->r("/composer.json не найден", 'red'); $this->out->r("/composer.json не найден", 'red');
} }
if (!is_dir(RESOURCES_DIR . '/tmp/app')) { if (!is_dir(RESOURCES_DIR . '/tmp/kernel')) {
mkdir(RESOURCES_DIR . '/tmp/app'); mkdir(RESOURCES_DIR . '/tmp/kernel');
} }
if (file_exists(KERNEL_DIR . '/manifest.json')) {
$manifest = json_decode(file_get_contents(KERNEL_DIR . '/manifest.json'), true);
$version = $manifest['version'] ?? '';
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel_v' . $version . '.igk');
}
else {
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk'); $this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk');
}
$this->files->recursiveRemoveDir(RESOURCES_DIR . '/tmp/ad/kernel/'); $this->files->recursiveRemoveDir(RESOURCES_DIR . '/tmp/ad/kernel/');
} }

View File

@ -2,7 +2,9 @@
namespace kernel\console\controllers; namespace kernel\console\controllers;
use kernel\App;
use kernel\console\ConsoleController; use kernel\console\ConsoleController;
use kernel\helpers\Debug;
class MainController extends ConsoleController class MainController extends ConsoleController
{ {
@ -12,4 +14,25 @@ class MainController extends ConsoleController
$this->out->r("Привет", "green"); $this->out->r("Привет", "green");
} }
public function actionHelp(): void
{
$routs = App::$collector->getData()->getStaticRoutes();
foreach ($routs as $rout => $data){
$additionalInfo = $data['GET'][3];
if (isset($additionalInfo['description']) and $additionalInfo['type'] === "console"){
$this->out->inLine($rout . " - ", "green");
$this->out->inLine($additionalInfo['description'], 'yellow');
$this->out->r("");
if (isset($additionalInfo['params'])){
foreach ($additionalInfo['params'] as $key => $param){
$this->out->inLine($key . " - ", "green");
$this->out->inLine($param, 'yellow');
$this->out->r("");
}
}
$this->out->r("");
}
}
}
} }

View File

@ -90,4 +90,33 @@ class ModuleController extends ConsoleController
} }
} }
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->createModuleByParams([
'slug' => $slug,
'model' => ucfirst($slug),
'author' => $author,
'name' => $name,
'label' => $label,
]);
$this->out->r("Модуль $slug создан", 'green');
}
} }

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
public string $migration;
/** /**
* Run the migrations. * Run the migrations.
*/ */

View File

@ -1,41 +1,96 @@
<?php <?php
use kernel\App; use kernel\App;
use kernel\console\controllers\MigrationController;
use Phroute\Phroute\RouteCollector; use Phroute\Phroute\RouteCollector;
App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]); App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]);
App::$collector->console("help", [\kernel\console\controllers\MainController::class, "actionHelp"]);
App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){ App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){
App::$collector->console('run', [\kernel\console\controllers\MigrationController::class, 'actionRun']); App::$collector->console('run',
App::$collector->console('init', [\kernel\console\controllers\MigrationController::class, 'actionCreateMigrationTable']); [MigrationController::class, 'actionRun'],
App::$collector->console('create', [\kernel\console\controllers\MigrationController::class, 'actionCreate']); additionalInfo: ['description' => 'Запуск существующих миграций']
App::$collector->console('rollback', [\kernel\console\controllers\MigrationController::class, 'actionRollback']); );
App::$collector->console('init',
[MigrationController::class, 'actionCreateMigrationTable'],
additionalInfo: ['description' => 'Инициализация миграций']
);
App::$collector->console('create',
[MigrationController::class, 'actionCreate'],
additionalInfo: ['description' => 'Создание миграции', 'params' => ['--name' => 'Название миграции', '--path' => 'Путь по которому будет создана миграция']]
);
App::$collector->console('rollback',
[MigrationController::class, 'actionRollback'],
additionalInfo: ['description' => 'Откатить миграции']
);
}); });
App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){ App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){
App::$collector->console('install', [\kernel\console\controllers\AdminThemeController::class, 'actionInstallTheme']); App::$collector->console('install',
App::$collector->console('uninstall', [\kernel\console\controllers\AdminThemeController::class, 'actionUninstallTheme']); [\kernel\console\controllers\AdminThemeController::class, 'actionInstallTheme'],
additionalInfo: ['description' => 'Установить тему админ-панели', 'params' => ['--path' => 'Путь к устанавливаемой теме']]
);
App::$collector->console('uninstall',
[\kernel\console\controllers\AdminThemeController::class, 'actionUninstallTheme'],
additionalInfo: ['description' => 'Удалить тему админ-панели', 'params' => ['--path' => 'Путь к удаляемой теме']]
);
}); });
App::$collector->group(["prefix" => "secure"], callback: function (RouteCollector $router){ App::$collector->group(["prefix" => "secure"], callback: function (RouteCollector $router){
App::$collector->console('create-secret-key', [\kernel\console\controllers\SecureController::class, 'actionCreateSecretKey']); App::$collector->console('create-secret-key',
[\kernel\console\controllers\SecureController::class, 'actionCreateSecretKey'],
additionalInfo: ['description' => 'Генерация секрктного ключа и запись его в .env']
);
}); });
App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector $router){ App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector $router){
App::$collector->console('init', [\kernel\console\controllers\AdminConsoleController::class, 'actionInit']); App::$collector->console('init',
[\kernel\console\controllers\AdminConsoleController::class, 'actionInit'],
additionalInfo: ['description' => 'Инициализация админ-панели']
);
}); });
App::$collector->group(["prefix" => "module"], callback: function (RouteCollector $router){ App::$collector->group(["prefix" => "module"], callback: function (RouteCollector $router){
App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']); App::$collector->console('install',
App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']); [\kernel\console\controllers\ModuleController::class, 'actionInstallModule'],
App::$collector->console('pack', [\kernel\console\controllers\ModuleController::class, 'actionPackModule']); additionalInfo: ['description' => 'Установка модуля', 'params' => ['--path' => 'Путь к устанавливаемому модулю']]
App::$collector->console('update', [\kernel\console\controllers\ModuleController::class, 'actionUpdateModule']); );
App::$collector->console('uninstall',
[\kernel\console\controllers\ModuleController::class, 'actionUninstallModule'],
additionalInfo: ['description' => 'Удалить модуль', 'params' => ['--path' => 'Путь к удаляемому модулю']]
);
App::$collector->console('pack',
[\kernel\console\controllers\ModuleController::class, 'actionPackModule'],
additionalInfo: ['description' => 'Заархивировать модуль', 'params' => ['--path' => 'Путь к модулю, который нужно заархивировать']]
);
App::$collector->console('update',
[\kernel\console\controllers\ModuleController::class, 'actionUpdateModule'],
additionalInfo: ['description' => 'Обновить модуль', 'params' => ['--path' => 'Путь к архиву с модулем']]
);
App::$collector->console('construct',
[\kernel\console\controllers\ModuleController::class, 'actionConstructModule'],
additionalInfo: ['description' => 'Сгенерировать модуль']
);
}); });
App::$collector->group(["prefix" => "kernel"], callback: function (RouteCollector $router){ App::$collector->group(["prefix" => "kernel"], callback: function (RouteCollector $router){
// App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']); App::$collector->console('pack',
// App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']); [\kernel\console\controllers\KernelController::class, 'actionPackKernel'],
App::$collector->console('pack', [\kernel\console\controllers\KernelController::class, 'actionPackKernel']); additionalInfo: ['description' => 'Заархивировать ядро', 'params' => ['--path' => 'Путь к ядру']]
App::$collector->console('update', [\kernel\console\controllers\KernelController::class, 'actionUpdateKernel']); );
App::$collector->console('update',
[\kernel\console\controllers\KernelController::class, 'actionUpdateKernel'],
additionalInfo: [
'description' => 'Обновить модуль',
'params' =>
[
'--path' => 'Путь к архиву ядра',
'bootstrap' => 'Обновить bootstrap',
'composer' => 'Обновить composer',
'env' => 'Обновить .env.example'
]
]
);
}); });

View File

@ -12,6 +12,7 @@ use kernel\models\Option;
use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\modules\module_shop_client\services\ModuleShopClientService;
use kernel\modules\user\service\UserService; use kernel\modules\user\service\UserService;
use kernel\Request; use kernel\Request;
use kernel\services\MigrationService;
use kernel\services\ModuleService; use kernel\services\ModuleService;
class ModuleController extends AdminController class ModuleController extends AdminController

8
kernel/manifest.json Normal file
View File

@ -0,0 +1,8 @@
{
"name": "Kernel",
"version": "0.1",
"author": "ITGuild",
"slug": "kernel",
"type": "kernel",
"description": "Kernel"
}

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
public string $migration;
/** /**
* Run the migrations. * Run the migrations.
*/ */

View File

@ -9,7 +9,7 @@ echo \kernel\helpers\Html::h(2, "Форма авторизации/регист
$form = new ActiveForm(); $form = new ActiveForm();
$form->beginForm("/admin/module_shop_client/auth/"); $form->beginForm("/admin/module_shop_client/auth/");
$form->field(\itguild\forms\inputs\TextInput::class, 'email', [ $form->field(\itguild\forms\inputs\EmailInput::class, 'email', [
'class' => "form-control", 'class' => "form-control",
'placeholder' => 'Email', 'placeholder' => 'Email',
]) ])

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
public string $migration;
/** /**
* Run the migrations. * Run the migrations.
*/ */

View File

@ -5,17 +5,22 @@ namespace kernel\modules\post;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\Module; use kernel\Module;
use kernel\modules\menu\service\MenuService; use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class PostModule extends Module class PostModule extends Module
{ {
public MenuService $menuService; public MenuService $menuService;
public MigrationService $migrationService;
public function __construct() public function __construct()
{ {
$this->menuService = new MenuService(); $this->menuService = new MenuService();
$this->migrationService = new MigrationService();
} }
public function init(): void public function init(): void
{ {
$this->migrationService->runAtPath("{KERNEL_MODULES}/post/migrations");
$this->menuService->createItem([ $this->menuService->createItem([
"label" => "Посты", "label" => "Посты",
"url" => "/admin/post", "url" => "/admin/post",
@ -26,5 +31,6 @@ class PostModule extends Module
public function deactivate(): void public function deactivate(): void
{ {
$this->menuService->removeItemBySlug("post"); $this->menuService->removeItemBySlug("post");
$this->migrationService->rollbackAtPath("{KERNEL_MODULES}/post/migrations");
} }
} }

View File

@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
public string $migration;
/** /**
* Run the migrations. * Run the migrations.
*/ */

View File

@ -3,16 +3,13 @@
/** /**
* @var \Illuminate\Database\Eloquent\Collection $contents * @var \Illuminate\Database\Eloquent\Collection $contents
* @var int $page_number * @var int $page_number
* @var \kernel\CgView $view
*/ */
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\modules\post\models\Post; use kernel\modules\post\models\Post;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\widgets\IconBtn\IconBtnCreateWidget; use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget; use kernel\widgets\IconBtn\IconBtnEditWidget;
@ -25,6 +22,11 @@ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
'baseUrl' => "/admin/post" 'baseUrl' => "/admin/post"
])); ]));
$view->setTitle("Список постов");
$view->setMeta([
'description' => 'Список постов системы'
]);
$entityRelation = new \kernel\EntityRelation(); $entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityRelationsBySlug("post"); $additionals = $entityRelation->getEntityRelationsBySlug("post");

View File

@ -7,9 +7,6 @@
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
use Itguild\EloquentTable\ViewEloquentTable; use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel; use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn;
use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget; use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget; use kernel\widgets\IconBtn\IconBtnListWidget;

View File

@ -36,6 +36,7 @@ class SecureRestController extends RestController
$res = []; $res = [];
if ($model) { if ($model) {
if (password_verify($data["password"], $model->password_hash)) { if (password_verify($data["password"], $model->password_hash)) {
if ($model->access_token_expires_at < date("Y-m-d H:i:s") or $model->access_token === null){
$model->access_token_expires_at = date("Y-m-d H:i:s", strtotime(App::$secure['token_expired_time'])); $model->access_token_expires_at = date("Y-m-d H:i:s", strtotime(App::$secure['token_expired_time']));
$model->access_token = match (App::$secure['token_type']) { $model->access_token = match (App::$secure['token_type']) {
"JWT" => TokenService::JWT($_ENV['SECRET_KEY'], 'HS256'), "JWT" => TokenService::JWT($_ENV['SECRET_KEY'], 'HS256'),
@ -44,6 +45,7 @@ class SecureRestController extends RestController
"hash" => TokenService::hash('sha256'), "hash" => TokenService::hash('sha256'),
default => TokenService::random_bytes(20), default => TokenService::random_bytes(20),
}; };
}
$res = [ $res = [
"access_token" => $model->access_token, "access_token" => $model->access_token,

View File

@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
public string $migration;
/** /**
* Run the migrations. * Run the migrations.
*/ */

View File

@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
public string $migration;
/** /**
* Run the migrations. * Run the migrations.
* *

View File

@ -0,0 +1,21 @@
<?php
namespace kernel\services;
class ConsoleService
{
public function runComposerRequire(string $package): void
{
exec("composer require $package");
}
public function runComposerRemove(string $package): void
{
exec("composer remove $package");
}
public function runCommand(string $command): void
{
exec($command);
}
}

View File

@ -36,4 +36,25 @@ class MigrationService
} }
} }
public function rollbackAtPath(string $path): void
{
$path = getConst($path);
try {
$filesystem = new Filesystem();
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), $filesystem);
$migrationFiles = $m->getMigrationFiles($path);
foreach ($migrationFiles as $name => $migrationFile){
$migrationInstance = $filesystem->getRequire($migrationFile);
$migrationInstance->migration = $name;
$migrationInstance->down();
$dmr->delete($migrationInstance);
}
} catch (\Exception $e) {
throw new \Exception('Не удалось откатить миграции');
}
}
} }

View File

@ -475,10 +475,13 @@ class ModuleService
{ {
if ($this->isServerAvailable()) { if ($this->isServerAvailable()) {
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
if (!$this->issetModuleShopToken()) { if (!$this->issetModuleShopToken()) {
return false; return false;
} }
$modules_info = json_decode($modules_info->getBody()->getContents(), true); $modules_info = json_decode($modules_info->getBody()->getContents(), true);
if (isset($modules_info)) {
$mod_info = $this->getModuleInfoBySlug($slug); $mod_info = $this->getModuleInfoBySlug($slug);
foreach ($modules_info as $mod) { foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug']) { if ($mod['slug'] === $mod_info['slug']) {
@ -486,6 +489,7 @@ class ModuleService
} }
} }
} }
}
return false; return false;
} }
@ -526,4 +530,52 @@ class ModuleService
return false; return false;
} }
public function createDirs(string $slug): void
{
mkdir(KERNEL_APP_MODULES_DIR . "/$slug");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/controllers");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/migrations");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/services");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models/forms");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/routs");
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/views");
mkdir(APP_DIR . "/modules/$slug");
mkdir(APP_DIR . "/modules/$slug/controllers");
mkdir(APP_DIR . "/modules/$slug/routs");
}
public function createModuleByParams(array $params): void
{
$slug = $params['slug'];
$model = $params['model'];
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/manifests/manifest_template', APP_DIR . "/modules/$slug/manifest.json", $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/controllers/kernel_controller_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/controllers/' . $model . 'Controller.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/controllers/app_controller_template', APP_DIR . '/modules/' . $slug . '/controllers/' . $model . 'Controller.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/routs/kernel_routs_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/routs/' . $slug . '.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/routs/app_routs_template', APP_DIR . '/modules/' . $slug . '/routs/' . $slug . '.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/module_files/kernel_module_file_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/' . $model . 'Module.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/module_files/app_module_file_template', APP_DIR . '/modules/' . $slug . '/' . $model . 'Module.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/models/model_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/models/' . $model . '.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/models/forms/create_form_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/models/forms/Create' . $model . 'Form.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/services/service_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/services/' . $model . 'Service.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/views/index_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/index.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/views/view_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/view.php', $params);
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/views/form_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/form.php', $params);
}
public function createModuleFileByTemplate(string $templatePath, string $filePath, array $params): void
{
$data = file_get_contents($templatePath);
foreach ($params as $key => $param){
$data = str_replace("{" . $key . "}", $param, $data);
}
file_put_contents($filePath, $data);
}
} }

View File

@ -32,7 +32,7 @@ class TokenService
*/ */
public static function md5(): string public static function md5(): string
{ {
return md5(microtime() . self::getSalt() . time()); return md5(microtime() . self::getSalt(10) . time());
} }
/** /**
@ -40,7 +40,7 @@ class TokenService
*/ */
public static function crypt(): string public static function crypt(): string
{ {
return crypt(microtime(), self::getSalt()); return crypt(microtime(), self::getSalt(20));
} }
/** /**
@ -48,15 +48,15 @@ class TokenService
*/ */
public static function hash(string $alg): string public static function hash(string $alg): string
{ {
return hash($alg, self::getSalt()); return hash($alg, self::getSalt(10));
} }
/** /**
* @throws RandomException * @throws RandomException
*/ */
public static function getSalt(): string public static function getSalt(int $length): string
{ {
return bin2hex(random_bytes(10)); return bin2hex(random_bytes($length));
} }
} }

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\{slug}\controllers;
class {model}Controller extends \kernel\app_modules\{slug}\controllers\{model}Controller
{
}

View File

@ -0,0 +1,98 @@
<?php
namespace kernel\app_modules\{slug}\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\{slug}\models\forms\Create{model}Form;
use kernel\app_modules\{slug}\models\{model};
use kernel\app_modules\{slug}\services\{model}Service;
class {model}Controller extends AdminController
{
private {model}Service ${slug}Service;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/{slug}/views/";
$this->{slug}Service = new {model}Service();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
${slug}Form = new Create{model}Form();
${slug}Form->load($_REQUEST);
if (${slug}Form->validate()){
${slug} = $this->{slug}Service->create(${slug}Form);
if (${slug}){
$this->redirect("/admin/{slug}/view/" . ${slug}->id);
}
}
$this->redirect("/admin/{slug}/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
${slug} = {model}::find($id);
if (!${slug}){
throw new Exception(message: "The {slug} not found");
}
$this->cgView->render("view.php", ['{slug}' => ${slug}]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = {model}::find($id);
if (!$model){
throw new Exception(message: "The {slug} not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
${slug} = {model}::find($id);
if (!${slug}){
throw new Exception(message: "The {slug} not found");
}
${slug}Form = new Create{model}Form();
${slug}Service = new {model}Service();
${slug}Form->load($_REQUEST);
if (${slug}Form->validate()) {
${slug} = ${slug}Service->update(${slug}Form, ${slug});
if (${slug}) {
$this->redirect("/admin/{slug}/view/" . ${slug}->id);
}
}
$this->redirect("/admin/{slug}/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
${slug} = {model}::find($id)->first();
${slug}->delete();
$this->redirect("/admin/{slug}/");
}
}

View File

@ -0,0 +1,11 @@
{
"name": "{name}",
"version": "0.1",
"author": "{author}",
"slug": "{slug}",
"description": "{name} module",
"module_class": "app\\modules\\{slug}\\{model}Module",
"module_class_file": "{APP}/modules/{slug}/{model}Module.php",
"routs": "routs/{slug}.php",
"migration_path": "migrations"
}

View File

@ -0,0 +1,25 @@
<?php
namespace kernel\app_modules\{slug}\models\forms;
use kernel\FormModel;
class Create{model}Form extends FormModel
{
public function rules(): array
{
// Заполнить массив правил
// Пример:
// return [
// 'label' => 'required|min-str-len:5|max-str-len:30',
// 'entity' => 'required',
// 'slug' => '',
// 'status' => ''
// ];
return [
];
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace kernel\app_modules\{slug}\models;
use Illuminate\Database\Eloquent\Model;
// Добавить @property
/**
* @property int $id
* @property int $status
*/
class {model} extends Model
{
const DISABLE_STATUS = 0;
const ACTIVE_STATUS = 1;
protected $table = '{slug}';
protected $fillable = []; // Заполнить массив. Пример: ['label', 'slug', 'status']
public static function labels(): array
{
// Заполнить массив
// Пример: [
// 'label' => 'Заголовок',
// 'entity' => 'Сущность',
// 'slug' => 'Slug',
// 'status' => 'Статус',
// ]
return [
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\{slug};
class {model}Module extends \kernel\app_modules\{slug}\{model}Module
{
}

View File

@ -0,0 +1,31 @@
<?php
namespace kernel\app_modules\{slug};
use kernel\helpers\Debug;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class {model}Module extends Module
{
public MenuService $menuService;
public function __construct()
{
$this->menuService = new MenuService();
}
public function init(): void
{
$this->menuService->createItem([
"label" => "{label}",
"url" => "/admin/{slug}",
"slug" => "{slug}",
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("{slug}");
}
}

View File

@ -0,0 +1,2 @@
<?php
include KERNEL_APP_MODULES_DIR . "/{slug}/routs/{slug}.php";

View File

@ -0,0 +1,20 @@
<?php
use kernel\App;
use kernel\CgRouteCollector;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "{slug}"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\{slug}\controllers\{model}Controller::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\{slug}\controllers\{model}Controller::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\{slug}\controllers\{model}Controller::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\{slug}\controllers\{model}Controller::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\app\modules\{slug}\controllers\{model}Controller::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\{slug}\controllers\{model}Controller::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\{slug}\controllers\{model}Controller::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\{slug}\controllers\{model}Controller::class, 'actionDelete']);
});
});
});

View File

@ -0,0 +1,39 @@
<?php
namespace kernel\app_modules\{slug}\services;
use kernel\helpers\Debug;
use kernel\app_modules\{slug}\models\{model};
use kernel\FormModel;
class {model}Service
{
public function create(FormModel $form_model): false|{model}
{
$model = new {model}();
// Пример заполнения:
// $model->content = $form_model->getItem('content');
// $model->user_id = $form_model->getItem('user_id');
// $model->title = $form_model->getItem('title');
// $model->slug = Slug::createSlug($form_model->getItem('title'), {model}::class); // Генерация уникального slug
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, {model} ${slug}): false|{model}
{
// Пример обновления:
// ${slug}->content = $form_model->getItem('content');
// ${slug}->user_id = $form_model->getItem('user_id');
if (${slug}->save()){
return ${slug};
}
return false;
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @var {model} $model
*/
use kernel\app_modules\{slug}\models\{model};
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/{slug}/edit/" . $model->id : "/admin/{slug}", 'multipart/form-data');
// Пример формы:
/*
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
'class' => "form-control",
'placeholder' => 'Заголовок поста',
'value' => $model->title ?? ''
])
->setLabel("Заголовок")
->render();
$form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params: [
'class' => "form-control",
'value' => $model->user_id ?? ''
])
->setLabel("Пользователи")
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
->render();
*/
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
'class' => "btn btn-warning",
'value' => 'Сбросить',
'typeInput' => 'reset'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -0,0 +1,68 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection ${slug}
* @var int $page_number
* @var \kernel\CgView $view
*/
use kernel\app_modules\{slug}\models\{model};
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$view->setTitle("Список {slug}");
$view->setMeta([
'description' => 'Список {slug} системы'
]);
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
//$table = new ListEloquentTable(new EloquentDataProvider({model}::class, [
// 'currentPage' => $page_number,
// 'perPage' => 8,
// 'params' => ["class" => "table table-bordered", "border" => "2"],
// 'baseUrl' => "/admin/{slug}"
//]));
$table = new \Itguild\Tables\ListJsonTable(json_encode(
[
'meta' => [
'total' => 0,
'totalWithFilters' => 0,
'columns' => [
'title',
'slug',
'status',
],
'perPage' => 5,
'currentPage' => 1,
'baseUrl' => '/admin/some',
'params' => [
'class' => 'table table-bordered',
'border' => 2
]
],
'filters' => [],
'data' => [],
]
));
$table->beforePrint(function () {
return IconBtnCreateWidget::create(['url' => '/admin/{slug}/create'])->run();
});
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/{slug}/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/{slug}/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/{slug}/delete/' . $row['id']])->run();
});
$table->create();
$table->render();

View File

@ -0,0 +1,25 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection ${slug}
*/
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel(${slug}, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/{slug}",
]));
$table->beforePrint(function () use (${slug}) {
$btn = IconBtnListWidget::create(['url' => '/admin/{slug}'])->run();
$btn .= IconBtnEditWidget::create(['url' => '/admin/{slug}/update/' . ${slug}->id])->run();
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/{slug}/delete/' . ${slug}->id])->run();
return $btn;
});
$table->create();
$table->render();

View File

@ -79,5 +79,7 @@ if ($moduleService->isActive('module_shop_client')) {
ModuleTabsWidget::create()->run(); ModuleTabsWidget::create()->run();
} }
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -1,4 +0,0 @@
<?php
echo "Hello IGFS!";
echo "test CI/CD";