/** Datei: plugins/rest/hooks/generator/controls.php **/ default", function( array $config, string $name, bool $required ) { return array_replace_recursive([ "key" => $name, "label" => ucfirst( $name ), "type" => REST\Generator\Data\Form\Control\Type::Text, "required" => $required ? "Pflichtfeld" : NULL, "validate" => [ "required" => "Bitte füllen Sie dieses Feld aus!", ], ], $config ); }); /* ### CONTROL TYPES ################################################ # */ Hooks::add("rest.generator::control.type->custom", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Custom, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->tel", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Tel, "validate" => [ "tel" => "Bitte geben Sie eine korrekte Telefonnummer ein!", ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->url", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::URL, "validate" => [ "url" => "Bitte geben Sie eine korrekte URL ein!", ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->text", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", $config, $name, $required ) ); }); Hooks::add("rest.generator::control.type->date", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Date, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->datetime", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::DateTime, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->time", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Time, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->file", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::File, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->range", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Range, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->email", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Email, "validate" => [ "email" => "Bitte geben Sie eine korrekte E-Mail-Adresse ein!", ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->radio", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Radio, "options" => [], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->select", function( array $config, string $name, bool $required, string|bool $choose = FALSE, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Select, "choose" => $choose == TRUE ? "-- Bitte wählen --" : $choose, "options" => [], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->hidden", function( array $config, string $name, string $value, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "label" => FALSE, "type" => REST\Generator\Data\Form\Control\Type::Hidden, "value" => $value, ], $config ), $name, FALSE ) ); }); Hooks::add("rest.generator::control.type->textarea", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Textarea, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->checkbox", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Checkbox, "options" => [], // "validate" => [ // "minChecked" => [ // "value" => 1, // "message" => "Mindestens 2 Optionen auswählen!", // ], // "maxChecked" => [ // "value" => 2, // "message" => "Maximal 2 Optionen auswählen!" // ], // ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->password", function( array $config, string $name, bool $confirm, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Password, "confirm" => $confirm ? "Password wiederholen" : FALSE, "validate" => [ "confirm" =>$confirm ? "Die Passwörter stimmen nicht überein!" : FALSE, ], ], $config ), $name, TRUE ) ); }); Hooks::add("rest.generator::control.type->number", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Number, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->progress", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Progress, ], $config ), $name, $required ) ); }); /* ### SPECIAL CONTROL TYPES ######################################## # */ Hooks::add("rest.generator::control.type->code", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Code, ], $config ), $name, $required ) ); }); /* ### CONTROL NAMES ################################################ # */ Hooks::add("rest.generator::control.name->email.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "E-Mail-Adresse", ]); }); Hooks::add("rest.generator::control.name->status.*", function( array $config ) { return array_replace_recursive( $config, [ "options" => Attribute\Status::getAll(), ]); }); /** Datei: plugins/rest/hooks/generator/actions.php **/ *", function( ...$args ) { $matches = array_pop( $args ); $config = array_shift( $args ); $plugin = array_shift( $args ); $route_id = array_shift( $args ) ?? "id"; $config = Hooks::filter("rest.generator::button.{$matches[0]}->{$matches[1]}", $config, $plugin, $route_id ); $config["title"] = $config["label"]; $config["label"] = NULL; return $config; }); /** Datei: plugins/rest/hooks/generator/buttons.php **/ default", function( array $config, ?string $label ) { if( isset( $config["action"] ) ) $config["action"] = preg_replace( '/\/+/', "/", $config["action"] ); return array_replace_recursive([ "label" => $label, "color" => REST\Generator\Config\Color::Primary, "type" => REST\Generator\Components\Button\Type::Button, ], $config ); }); /* ### BUTTON TYPES ################################################# # */ Hooks::add("rest.generator::button.type->submit", function( array $config, ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->submit.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-send-fill", "type" => REST\Generator\Components\Button\Type::Submit, ], $config ), $label ?? "Absenden" ) ); }); Hooks::add("rest.generator::button.type->delete", function( array $config, ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->delete.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-trash", "color" => REST\Generator\Config\Color::Danger, "type" => REST\Generator\Components\Button\Type::Submit, ], $config ), $label ?? "Löschen" ) ); }); Hooks::add("rest.generator::button.type->cancel", function( array $config, ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->cancel.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-x-lg", "color" => REST\Generator\Config\Color::Primary, "type" => REST\Generator\Components\Button\Type::Cancel, ], $config ), $label ?? "Abbrechen" ) ); }); Hooks::add("rest.generator::button.type->sort", function( array $config, ?string $column, string $order = "asc", ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->sort.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-sort-down-alt", "color" => REST\Generator\Config\Color::Default, "type" => REST\Generator\Components\Button\Type::Button, "title" => $label ?? "Sortieren", "order" => [ "column" => strtolower( $column ), "order" => strtolower( $order ), ], ], $config ), "" ) ); }); /* ### BUTTON NAMES ################################################# # */ Hooks::add("rest.generator::button.name->create", function( array $config, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->create.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "create", "label" => "Hinzufügen", "color" => REST\Generator\Config\Color::Primary, "icon" => "bi bi-plus-lg", "action" => "/{$plugin}/create", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->edit", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->edit.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "edit", "label" => "Bearbeiten", "color" => REST\Generator\Config\Color::Primary, "icon" => "bi bi-pencil", "action" => "/{$plugin}/{{$route_id}}", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->list", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->list.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "list", "label" => "Übersicht", "color" => REST\Generator\Config\Color::Secondary, "icon" => "bi bi-list", "action" => "/{$plugin}/{{$route_id}}", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->link", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->link.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "link", "label" => "Öffnen", "color" => REST\Generator\Config\Color::Default, "icon" => REST\Generator\Config\Icon::BoxArrowUpRight, "href" => $config["action"], "target" => "_blank", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->delete", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->delete.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "delete", "label" => "Löschen", "color" => REST\Generator\Config\Color::Danger, "icon" => "bi bi-trash", "action" => "/{$plugin}/{{$route_id}}/delete", ], $config ), NULL ) ); }); /** Datei: plugins/rest/hooks/generator/enum/icon.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook config::loaded * * @since 1.0.0 File is created */ $pluginDir = realpath( PLUGINS_DIR ); $hashFile = "{$pluginDir}/rest/assets/bootstrap-icons.hash"; $emojiFile = "{$pluginDir}/rest/assets/icon_emoji.json"; $inputFile = "{$pluginDir}/rest/assets/bootstrap-icons.json"; $outputFile = "{$pluginDir}/rest/library/ARUNOX/Plugins/REST/Generator/Config/Icon.php"; if( !file_exists( $emojiFile ) ) return; if( !file_exists( $inputFile ) ) return; $currentHash = implode( ".", [ md5_file( $inputFile ), md5_file( $emojiFile ), ]); $previousHash = file_exists( $hashFile ) ? file_get_contents( $hashFile ) : ""; if( $currentHash === $previousHash ) return; $emojis = file_get_contents( $emojiFile ); $emojis = json_decode( $emojis, TRUE ); $input = file_get_contents( $inputFile ); $input = json_decode( $input, TRUE ); $output = []; if( !is_array( $input ) ) return; function toReadableEnumCase( string $iconName ): string { $parts = explode("-", $iconName ); if( is_numeric( $parts[0] ) ) { $number = array_shift($parts ); $prev = array_shift($parts ); $parts = array_merge( [ $prev, $number ], $parts ); $parts = array_filter( $parts, fn( $item ) => $item !== NULL ); } return implode("", array_map("ucfirst", $parts ) ); } $input = array_map( fn( $key, $code ) => [ "icon" => "bi-{$key}", "name" => toReadableEnumCase( $key ), "code" => sprintf( '\\%04x', $code ), "emoji" => $emojis["bi-{$key}"] ?? NULL, ], array_keys( $input ), array_values( $input ) ); $input = array_filter( $input, fn( $item ) => !is_numeric( $item["name"] ) ); // show( $input ); $output[] = " \"{$icon["code"]}\","; } $output[] = " };"; $output[] = " }"; $output[] = " public function emoji() {"; $output[] = " return match( \$this ) {"; foreach( $input as $icon ) { $output[] = " Icon::{$icon["name"]} => \"{$icon["emoji"]}\","; } $output[] = " };"; $output[] = " }"; $output[] = " }"; $output = implode( "\n", $output ); // show( htmlentities( $output ) ); file_put_contents( $outputFile, $output ); file_put_contents( $hashFile, $currentHash ); /** Datei: plugins/rest/hooks/generator/columns.php **/ default", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible ) { return array_replace_recursive([ "key" => $name, "label" => ucfirst( $name ), "type" => REST\Generator\Data\Table\Column\Type::Text, "visible" => $visible, "sortable" => $sortable, "searchable" => $searchable, "color" => [ "color" => REST\Generator\Config\Color::Default, "target" => "icon" ], ], $config ); }); /* ### COLUMN TYPES ################################################# # */ Hooks::add("rest.generator::column.type->date", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Date, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->tel", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Tel, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->url", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::URL, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->text", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", $config, $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->amount", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Amount, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->time", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Time, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->email", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Email, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->actions", function( array $config, array $buttons, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->actions.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Actions, "buttons" => $buttons, ], $config ), "actions", FALSE, FALSE, TRUE ) ); }); Hooks::add("rest.generator::column.type->datetime", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::DateTime, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->icon", function( array $config, string $name, array $options, string $plugin ) { $hook = Hooks::parseName( $plugin ); $config = Hooks::filter("rest.generator::column->default", array_replace_recursive([ "icon" => "bi-toggles", "type" => REST\Generator\Data\Table\Column\Type::Icon, "color" => [ "color" => REST\Generator\Config\Color::Default, "target" => "icon" ], "options" => $options, ], $config ), $name, FALSE, FALSE, TRUE ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", array_replace_recursive( $config, [ "title" => $config["label"], "label" => NULL, ])); }); Hooks::add("rest.generator::column.type->status", function( array $config, string $name, array $options, string $plugin, string $route_id = "id" ) { return Hooks::filter("rest.generator::column.type->icon", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Status, "action" => [ "method" => "PATCH", "route" => "/api/v1/{$plugin}/{{$route_id}}/{$name}", ], ], $config ), $name, $options, $plugin ); }); /* ### COLUMN NAMES ################################################# # */ Hooks::add("rest.generator::column.name->status.*", function( array $config ) { return array_replace_recursive([ "options" => Attribute\Status::getAll(), ], $config ); }); Hooks::add("rest.generator::column.name->email.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "E-Mail-Adresse", ]); }); Hooks::add("rest.generator::column.name->date_create.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Erstellt am", ]); }); Hooks::add("rest.generator::column.name->date_edit.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Bearbeitet am", ]); }); Hooks::add("rest.generator::column.name->actions.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Aktionen", ]); });