/** Datei: plugins/dev/library/ARUNOX/Plugins/Dev/Plugins/Model.php **/ toArray() ); } return $plugins; } public static function get( int|string|array $name, string|array $columns = ["*"] ) : array|false|BaseEntity { return new Entity( Plugins::get( $name )->toArray() ); } public static function getClasses( string $id ) : array { $prefix = realpath( PLUGINS_DIR . "/{$id}/library" ); $classes = glob_recursive( "{$prefix}/*/Model.php"); foreach( $classes as &$class ) { $class = realpath( $class ); $class = str_replace( "{$prefix}/", "", $class ); $class = str_replace( ".php", "", $class ); $class = str_replace( DIRECTORY_SEPARATOR, "\\", $class ); if( !class_exists( $class ) ) { $class = NULL; } } return array_filter( $classes ); } public static function getTables( string $id ) : array { $tables = []; $classes = Model::getClasses( $id ); foreach( $classes as $class ) { $table = $class::getTable(); if( Database::existsTable( $table ) ) { $tables[] = $table; $tables[] = Database::getTables( "{$table}_%"); } } $tables = array_reduce_recursive( $tables ); $tables = array_values( $tables ); return $tables; } public static function getSchemas( string $id ) : array { $tables = Model::getTables( $id ); $schema = []; foreach( $tables as $table ) { $schema[ $table ] = Database::getSchema( $table ); } return $schema; } public static function getVersion( string $version, ?int $type = NULL ) { $version = explode( ".", $version ?? "" ); $version = array_pad( $version, 3, "0" ); $version = array_reverse( $version ); if( $type !== NULL ) { $version[ $type ]++; } $version = array_reverse( $version ); $version = implode( ".", $version ); return $version; } /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/dev/library/ARUNOX/Plugins/Dev/Plugins/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Dev\Plugins\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/dev/plugins", "label" => "Plugins", "icon" => "bi bi-puzzle", "menu" => "development", ]; return $routes; }); } } /** Datei: plugins/dev/library/ARUNOX/Plugins/Dev/Plugins/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Dev\Plugins\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Dev; use ARUNOX\API\BaseController; use ARUNOX\Database\Attribute; use ARUNOX\Plugins\Systems\Ignore; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Plugin nicht gefunden", "created" => "Plugin Version wurde erfolgreich erstellt", "updated" => "Plugin Version wurde erfolgreich aktualisiert", "notcreated" => "Plugin Version konnte nicht erstellt werden", "notupdated" => "Plugin Version konnte nicht aktualisiert werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /dev/plugins * @route.description Listet alle Agents */ public static function getAll() : array { return Dev\Plugins\Model::getAll(); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public function versionCreate( string $id, array $data ) { if( $result = Dev\Plugins\Model::get( $id ) ) { if( $result->versionCreate( $data["version"] ) ) { REST\Response::addNotify( "success", static::$NOTIFY["created"] ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notcreated"] ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /dev/plugins * @route.description REST-Konfiguration für Agenten-Tabelle */ public static function restConfigOverview() { return REST\Response::addWrapper( "overview", "Plugins" ) ->get() ->setApi( "/dev/plugins" ) ->setAction( "/dev/plugins/{hashid}" ) ->setOrder( "plugin", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "dev/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "label", TRUE, TRUE, TRUE, "dev/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "icon" => "bi-eye", "options" => Dev\Plugins\Ignore::getAll(), ], "ignore", [], "dev/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "icon" => "bi-lightning-charge-fill", "options" => Dev\Plugins\Preload::getAll(), ], "preload", [], "dev/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "version", TRUE, TRUE, TRUE, "dev/plugins" )) ->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [ "label" => "Versionieren", "icon" => "bi bi-tag", "color" => REST\Generator\Config\Color::Secondary, "action" => "/dev/plugins/{hashid}/version", ], "dev/plugins" )) ->parent() ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "author", TRUE, TRUE, TRUE, "dev/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "dev/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "dev/plugins" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "dev/plugins", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "dev/plugins", "hashid" )) ; } public static function restConfigVersion( string $id ) { $data = Dev\Plugins\Model::get( $id ); return REST\Response::addModal( "details", "Versionieren" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->setData( $data ) ->get() ->setAction( "/dev/plugins/{id}/version", "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "dev/plugins" )) ->addField(...Hooks::filter( "rest.generator::control.type->radio", [ "options" => $data->getVersionsAsOptions(), "value" => $data->getPatchVersion(), ], "version", TRUE, FALSE, "dev/plugins" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ } /** Datei: plugins/dev/library/ARUNOX/Plugins/Dev/Plugins/Preload.php **/ [ "color" => REST\Generator\Config\Color::Medium, "label" => "Inaktiv", "icon" => "bi bi-lightning-charge" ], 1 => [ "color" => REST\Generator\Config\Color::Info, "label" => "Aktiv", "icon" => "bi bi-lightning-charge-fill" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/dev/library/ARUNOX/Plugins/Dev/Plugins/Entity.php **/ Ignore::class, "preload" => Preload::class, "status" => Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } public function versionCreate( $version ) { $path = PLUGINS_DIR . "/{$this->id}/config/schema"; $schema = Model::getSchemas( $this->id ); $schema = var_export( $schema, TRUE ); @mkdir( $path, 0755, TRUE ); $result = file_put_contents( PLUGINS_DIR . "/{$this->id}/config/schema/v{$version}.php", "path}/config.php"; $config = file_get_contents( $file ); $config = preg_replace( "/(@version\s+)([0-9]+(?:\.[0-9]+)+)/", "\${1}{$version}", $config ); // if( $version != $this->getVersion() ) { // $config = preg_replace( "/(@version\s+)([0-9]+(?:\.[0-9]+)+)/", "\${1}{$version}", $config ); // } file_put_contents( $file, $config ); $this->version = $version; } return $result; } public function getVersionsAsOptions() { $versions = []; $versions[] = [ "value" => $this->getCurrentVersion(), "label" => "{$this->getCurrentVersion()} (Update)", ]; $versions[] = [ "value" => $this->getPatchVersion(), "label" => "{$this->getPatchVersion()} (PATCH)", ]; $versions[] = [ "value" => $this->getMinorVersion(), "label" => "{$this->getMinorVersion()} (MINOR)", ]; $versions[] = [ "value" => $this->getMajorVersion(), "label" => "{$this->getMajorVersion()} (MAJOR)", ]; return $versions; } public function getCurrentVersion() { return Model::getVersion( $this->version ); } public function getPatchVersion() { return Model::getVersion( $this->version, 0 ); } public function getMinorVersion() { return Model::getVersion( $this->version, 1 ); } public function getMajorVersion() { return Model::getVersion( $this->version, 2 ); } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( $values ) { foreach( $values as $name => $value ) { $this->{$name} = $value; } parent::__construct(); } } /** Datei: plugins/dev/library/ARUNOX/Plugins/Dev/Plugins/Ignore.php **/ [ "color" => REST\Generator\Config\Color::Success, "label" => "Anzeigen", "icon" => "bi bi-eye" ], 1 => [ "color" => REST\Generator\Config\Color::Danger, "label" => "Ignorieren", "icon" => "bi bi-eye-slash" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ }