session errors

This commit is contained in:
Kavalar 2024-10-11 17:02:35 +03:00
parent 5b9386f970
commit 7cf3708e4d
9 changed files with 146 additions and 8174 deletions

View File

@ -14,7 +14,8 @@
"itguild/forms": "^0.1.1",
"samejack/php-argv": "dev-master",
"itguild/eloquent-table": "^0.4.1",
"ext-zip": "*"
"ext-zip": "*",
"josantonius/session": "^2.0"
},
"autoload": {
"psr-4": {

109
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "89f7ae78ea05c4cc22cc32f405d736ac",
"content-hash": "e4f9dc9c939855869a503f576ef50d53",
"packages": [
{
"name": "brick/math",
@ -337,16 +337,16 @@
},
{
"name": "illuminate/collections",
"version": "v11.24.1",
"version": "v11.27.2",
"source": {
"type": "git",
"url": "https://github.com/illuminate/collections.git",
"reference": "f205537e0ad131a1a87cb3cf04924e9edda4f2b1"
"reference": "4d333ea19a27230b424b9af56f34cd658b5bbce2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/f205537e0ad131a1a87cb3cf04924e9edda4f2b1",
"reference": "f205537e0ad131a1a87cb3cf04924e9edda4f2b1",
"url": "https://api.github.com/repos/illuminate/collections/zipball/4d333ea19a27230b424b9af56f34cd658b5bbce2",
"reference": "4d333ea19a27230b424b9af56f34cd658b5bbce2",
"shasum": ""
},
"require": {
@ -388,11 +388,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2024-09-16T14:32:15+00:00"
"time": "2024-09-27T14:54:48+00:00"
},
{
"name": "illuminate/conditionable",
"version": "v11.24.1",
"version": "v11.27.2",
"source": {
"type": "git",
"url": "https://github.com/illuminate/conditionable.git",
@ -438,16 +438,16 @@
},
{
"name": "illuminate/container",
"version": "v11.24.1",
"version": "v11.27.2",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
"reference": "d6aca7c315d68cb6807c139facd7ea134b4f5104"
"reference": "bc49d144a20b0d432e1ac812c9e056594b6c6480"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/container/zipball/d6aca7c315d68cb6807c139facd7ea134b4f5104",
"reference": "d6aca7c315d68cb6807c139facd7ea134b4f5104",
"url": "https://api.github.com/repos/illuminate/container/zipball/bc49d144a20b0d432e1ac812c9e056594b6c6480",
"reference": "bc49d144a20b0d432e1ac812c9e056594b6c6480",
"shasum": ""
},
"require": {
@ -485,11 +485,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2024-09-20T12:51:05+00:00"
"time": "2024-10-08T13:34:53+00:00"
},
{
"name": "illuminate/contracts",
"version": "v11.24.1",
"version": "v11.27.2",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
@ -672,7 +672,7 @@
},
{
"name": "illuminate/macroable",
"version": "v11.24.1",
"version": "v11.27.2",
"source": {
"type": "git",
"url": "https://github.com/illuminate/macroable.git",
@ -718,16 +718,16 @@
},
{
"name": "illuminate/support",
"version": "v11.24.1",
"version": "v11.27.2",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
"reference": "f1bcdb2205223a70f01ec1750669689154037444"
"reference": "a567431e4820363d0bc28bdf14914ab16a2e63ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/f1bcdb2205223a70f01ec1750669689154037444",
"reference": "f1bcdb2205223a70f01ec1750669689154037444",
"url": "https://api.github.com/repos/illuminate/support/zipball/a567431e4820363d0bc28bdf14914ab16a2e63ef",
"reference": "a567431e4820363d0bc28bdf14914ab16a2e63ef",
"shasum": ""
},
"require": {
@ -790,7 +790,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2024-09-17T15:56:18+00:00"
"time": "2024-10-08T18:54:07+00:00"
},
{
"name": "itguild/eloquent-table",
@ -888,11 +888,11 @@
},
{
"name": "itguild/tables",
"version": "1.0.7",
"version": "1.0.8",
"source": {
"type": "git",
"url": "https://git.itguild.info/ItGuild/tables",
"reference": "02a3e52b7d365c44a32b7580a2246d47ea032736"
"reference": "5f46431d4562d2b4d8bff43b446fef82ecf73b83"
},
"type": "library",
"autoload": {
@ -910,7 +910,70 @@
"email": "apuc06@mail.ru"
}
],
"time": "2024-09-24T12:42:55+00:00"
"time": "2024-10-11T13:31:11+00:00"
},
{
"name": "josantonius/session",
"version": "v2.0.9",
"source": {
"type": "git",
"url": "https://github.com/josantonius/php-session.git",
"reference": "1547efc7874e83cf720a3df57575d61b3dee107a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/josantonius/php-session/zipball/1547efc7874e83cf720a3df57575d61b3dee107a",
"reference": "1547efc7874e83cf720a3df57575d61b3dee107a",
"shasum": ""
},
"require": {
"php": "^8.0"
},
"require-dev": {
"phpmd/phpmd": "^2.12",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Josantonius\\Session\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Josantonius",
"email": "hello@josantonius.dev",
"homepage": "https://josantonius.dev",
"role": "Developer"
}
],
"description": "PHP library for handling sessions.",
"keywords": [
"php",
"session"
],
"support": {
"discussions": "https://github.com/josantonius/php-session/discussions",
"issues": "https://github.com/josantonius/php-session/issues",
"source": "https://github.com/josantonius/php-session"
},
"funding": [
{
"url": "https://github.com/Josantonius",
"type": "github"
}
],
"time": "2024-05-20T09:12:44+00:00"
},
{
"name": "madesimple/php-arrays",
@ -2499,5 +2562,5 @@
"ext-zip": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.3.0"
}

View File

@ -3,6 +3,7 @@
* @var $content
* @var string $resources
*/
\Josantonius\Session\Facades\Session::start();
?>
<!doctype html>
<html lang="en">
@ -14,6 +15,7 @@
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
</head>
<body>
@ -68,7 +70,13 @@
</div>
</div>
</nav>
<?php if (\Josantonius\Session\Facades\Session::get("error", false)): ?>
<div class="alert alert-danger alert-dismissible" id="mainAlert">
<?= \Josantonius\Session\Facades\Session::get("error"); ?>
<?php \Josantonius\Session\Facades\Session::remove("error"); ?>
<button type="button" class="btn-close" id="closeAlertBtn"></button>
</div>
<?php endif; ?>
<?= $content ?>
</div>
</div>

View File

@ -3,6 +3,7 @@
namespace kernel\controllers;
use DirectoryIterator;
use Josantonius\Session\Facades\Session;
use kernel\AdminController;
use kernel\helpers\Debug;
use kernel\models\Option;
@ -59,7 +60,12 @@ class ModuleController extends AdminController
public function actionActivate(): void
{
$request = new Request();
$this->moduleService->setActiveModule($request->get("slug"));
$active_res = $this->moduleService->setActiveModule($request->get("slug"));
if (!$active_res){
Session::start();
Session::set("error", implode(";", $this->moduleService->getErrors()));
$this->redirect("/admin", 302);
}
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
$this->cgView->render("view.php", ['data' => $mod_info]);
@ -68,7 +74,7 @@ class ModuleController extends AdminController
public function actionDeactivate(): void
{
$request = new Request();
$this->moduleService->unsetActiveModule($request->get("slug"));
$this->moduleService->deactivateModule($request->get("slug"));
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
$this->cgView->render("view.php", ['data' => $mod_info]);

View File

@ -11,6 +11,7 @@ use ZipArchive;
class ModuleService
{
protected array $errors = [];
public function getModuleInfo(string $module): false|array|string
{
@ -26,6 +27,16 @@ class ModuleService
return $info;
}
public function getErrors(): array
{
return $this->errors;
}
public function addError($msg): void
{
$this->errors[] = $msg;
}
public function getModuleInfoBySlug(string $slug): false|array|string
{
return $this->getModuleInfo($this->getModuleDir($slug));
@ -74,12 +85,16 @@ class ModuleService
$active_modules_info->save();
}
public function setActiveModule(string $module): void
/**
* @param string $module
* @return bool
*/
public function setActiveModule(string $module): bool
{
$active_modules_info = Option::where("key", "active_modules")->first();
$active_modules = json_decode($active_modules_info->value);
if (in_array($module, $active_modules->modules)) {
throw new \Exception("$module module is already activated");
return true;
}
$module_info = $this->getModuleInfoBySlug($module);
@ -87,7 +102,8 @@ class ModuleService
$dependence_array = explode(',', $module_info['dependence']);
foreach ($dependence_array as $depend) {
if (!in_array($depend, $active_modules->modules)) {
throw new \Exception("first activate the $depend module");
$this->addError("first activate the $depend module");
return false;
}
}
}
@ -96,17 +112,20 @@ class ModuleService
$active_modules_info->value = json_encode($active_modules, JSON_UNESCAPED_UNICODE);
$active_modules_info->save();
return true;
}
/**
* @throws \Exception
* @param string $module
* @return bool
*/
public function unsetActiveModule(string $module): void
public function deactivateModule(string $module): bool
{
$active_modules_info = Option::where("key", "active_modules")->first();
$active_modules = json_decode($active_modules_info->value);
if (!in_array($module, $active_modules->modules)) {
throw new \Exception("$module module is already activated");
return true;
}
$dependence_array = $this->getDependencies();
@ -121,7 +140,8 @@ class ModuleService
}
if ($str_for_exception !== '') {
throw new \Exception("You can not deactivate $module module. First deactivate modules: $str_for_exception");
$this->addError("You can not deactivate $module module. First deactivate modules: $str_for_exception");
return false;
}
unset($active_modules->modules[array_search($module, $active_modules->modules)]);
@ -130,6 +150,8 @@ class ModuleService
$active_modules_info->value = json_encode($active_modules, JSON_UNESCAPED_UNICODE);
$active_modules_info->save();
return true;
}
public function getModuleDir(string $slug)

View File

@ -25,6 +25,7 @@ $info_to_table['data'] = $modules_info;
$table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug'];
if ($moduleService->isActive($slug)){
@ -41,6 +42,7 @@ $table->addAction(function ($row, $url) use ($moduleService){
return $btn;
});
$table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug'];
return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -16,4 +16,8 @@
$('#sidebar').toggleClass('active');
});
$("#closeAlertBtn").click(function () {
$("#mainAlert").alert("close");
});
})(jQuery);