/** Datei: library/ARUNOX/API/PHP/Attributes/Controller/Label.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Controller; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS )] class Label extends PHP\Attributes\Database\Options\Label {} /** Datei: library/ARUNOX/API/PHP/Attributes/Controller/Notifications/Helper.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Controller\Notifications; use Attribute; use ARUNOX\API\PHP; use ReflectionClass; trait Helper { /* ### VARIABLES ################################################ # */ protected static array $__CACHED_NOTIFIES = []; /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public static function getNotify( string|array $type, null|string $label = NULL ) : string|bool { return static::getNotification( $type, $label ); } public static function getNotification( string|array $type, null|string|array $label = NULL ) : string|bool { $notify = static::resolveNotificationsFromClass( ...(array)$type ); if( $label ) { $label = new Label( ...(array)$label ); $label = $label->getLabel() ?? NULL; } if( $label == NULL ) { $label = static::getLabel(); } if( $label ) { $notify = preg_replace_callback( '/\{\$LABEL\.([a-z]+)\}/', fn( $match ) => $label[ $match[1] ], $notify ); } return $notify; } public static function getNotifications() : array { return static::resolveNotificationsFromClass(); } /* ### PRIVATE STATIC FUNCTIONS ################################# # */ private static function resolveNotificationsFromClass( ...$type ) : string|array { $reflection = new ReflectionClass( static::class ); $attributes = []; $type = implode( ".", $type ); if( !isset( static::$__CACHED_NOTIFIES[ static::class ] ) ) { do { foreach( $reflection->getAttributes( PHP\Attributes\Controller\Notifications::class ) as $attribute ) { $instance = $attribute->newInstance(); if( key_exists( $instance->type, $attributes ) ) continue; $attributes[ $instance->type ] = $instance->message; } $reflection = $reflection->getParentClass(); } while ($reflection); static::$__CACHED_NOTIFIES[ static::class ] = $attributes; } if( $type ) return static::$__CACHED_NOTIFIES[ static::class ][ $type ] ?? "Unbekannter Fehler!"; else return static::$__CACHED_NOTIFIES[ static::class ] ?? []; } } /** Datei: library/ARUNOX/API/PHP/Attributes/Controller/Notifications/Notifications.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Controller; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE )] class Notifications { use PHP\Attributes\Magic\Get\Helper; /* ### VARIABLES ################################################ # */ /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $type, protected string $message, protected bool $default = FALSE ){} } /** Datei: library/ARUNOX/API/PHP/Attributes/Controller/Icon.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Controller; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS )] class Icon extends PHP\Attributes\Database\Options\Icon {} /** Datei: library/ARUNOX/API/PHP/Attributes/Controller/Route/Route.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Controller; use Attribute; use ARUNOX\API\PHP; use ARUNOX\API\BaseController; #[Attribute( Attribute::TARGET_CLASS )] class Route { use PHP\Attributes\Magic\Get\Helper; /* ### VARIABLES ################################################ # */ protected string $route = "/"; /* ### PUNLIC FUNCTIONS ######################################### # */ public function get() { return $this->route; } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( ... $route ){ $segments = []; foreach( $route as $item ) { if( class_exists( $item ) ) { if( method_exists( $item, "getRoute" ) ) { array_unshift( $segments, $item::getRoute() ?? NULL ); } continue; } if( is_string( $item ) ) array_unshift( $segments, $item ); } $segments = array_filter( $segments ); $segments = implode( "/", $segments ); $segments = preg_replace( "/\/+/", "/", $segments ); $segments = strtolower( $segments ); $this->route = $segments; } } /** Datei: library/ARUNOX/API/PHP/Attributes/Controller/Route/Helper.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Controller\Route; use ARUNOX\API\PHP; use ReflectionClass; trait Helper { /* ### VARIABLES ################################################ # */ protected static array $__CACHED_ROUTES = []; /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public static function getRoute( ...$suffixes ) : string { $route = static::resolveRouteFromClass(); $route = preg_replace( "/\\/+/", "/", $route ); $route = preg_replace( "/\\/#/", "#", $route ); $route = explode( "/", $route ); $route = array_filter( $route ); foreach( $suffixes as $suffix ) { if( preg_match( "/([0-9]+):(.*)/", $suffix, $matches ) ) { $pos = $matches[1] * -1; $prev = array_slice( $route, 0, $pos ); $next = array_slice( $route, $pos ); $route = [ ...$prev, $matches[2], ...$next ]; continue; } $route[] = $suffix; } $route = array_filter( $route ); $route = implode( "/", $route ); $route = "/{$route}"; return $route; } /* ### PRIVATE STATIC FUNCTIONS ################################# # */ private static function resolveRouteFromClass() : string { $reflection = new ReflectionClass( static::class ); $attributes = ""; if( !isset( static::$__CACHED_ROUTES[ static::class ] ) ) { do { foreach( $reflection->getAttributes( PHP\Attributes\Controller\Route::class ) as $attribute ) { $instance = $attribute->newInstance(); if( !empty( $attributes ) ) break 2; $attributes = $instance->get(); } $reflection = $reflection->getParentClass(); } while ($reflection); static::$__CACHED_ROUTES[ static::class ] = $attributes; } return static::$__CACHED_ROUTES[ static::class ] ?? ""; } }