devsuite/cds/actions/Crispage/DevSuite/ClassManagerAction.php
2024-05-27 00:44:14 -04:00

99 lines
2.4 KiB
PHP

<?php
namespace Crispage\DevSuite;
defined("ROOT") or die();
use \Crispage\Auth\CorePermissions;
class ClassManagerAction extends \Crispage\Framework\Action {
public static function getExtensionInfo(): array {
return [
"id" => "crispage.devsuite.actions.classmanager",
"version" => VERSION,
"package" => "crispage.devsuite"
];
}
public function __construct(\Crispage $app, array $data) {
parent::__construct($app, $data);
}
public function run(): void {
$this->app->page->data["title"] = $this->app->i18n->translate("{%CDS_CLASS_MANAGER}");
if (!$this->app->auth->userHasPermission(
CorePermissions::MANAGE_EXTENSIONS
)) {
$this->app->page->setPersistentMessage(
"unauthorized", "Unauthorized", "danger"
);
$this->app->page->actionFinished();
};
$action = strval($this->app->request->params["action"] ?? "");
switch ($action) {
case "":
break;
case "register": {
$classname = strval($this->app->request->params["classname"] ?? "");
$type = strval($this->app->request->params["type"] ?? "");
if (!$this->app->cds->registerExtension($classname, $type))
$err = "Could not register $classname as $type";
break;
}
case "unregister": {
$exts = $this->app->request->params["exts"] ?? [];
if (empty($exts) || !is_array($exts))
break;
$this->app->cds->unregisterExtensions($exts);
break;
}
case "plugin_create": {
$plugin = strval(
$this->app->request->params["ext"] ?? ""
);
$priority = intval(
$this->app->request->params["priority"] ?? 0
);
$this->app->cds->createPlugin($plugin);
break;
}
case "plugin_delete": {
$plugin = strval(
$this->app->request->params["ext"] ?? ""
);
$this->app->cds->deletePlugin($plugin);
break;
}
default:
$err = "Invalid action";
}
if (isset($err)) {
$this->app->page->data["messages"]["error"] = [
"content" => $err,
"color" => "danger"
];
}
elseif (strlen($action)) {
$this->app->page->data["messages"]["success"] = [
"content" => "Success",
"color" => "success"
];
}
$com_main = $this->app->page->createComponent(
"\\Crispage\\DevSuite\\ClassManagerComponent",
["extensions" => $this->app->cds->getExtensions()]
);
$this->app->page->setMainComponent($com_main);
$this->app->page->actionFinished();
}
}
?>