/** Datei: library/ARUNOX/API/PHP/Attributes/Database/Attributes/Attributes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database; use Attribute; use ARUNOX\API\PHP; use ARUNOX\Database; #[Attribute( Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE )] class Attributes { use PHP\Attributes\Magic\Get\Helper; /* ### VARIABLES ################################################ # */ protected static array $ATTRIBUTES = [ "status" => Database\Attribute\Status::class, "date_create" => Database\Attribute\DateTime::class, "date_edit" => Database\Attribute\DateTime::class, ]; /* ### PROTECTED FUNCTIONS ###################################### # */ protected function getClass() { return $this->class ?? ( static::$ATTRIBUTES[ $this->column ] ?? NULL ); } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $column, protected null|string $class = NULL ){ if( !$class ) $this->class = $this->getClass( $this->column ); } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Attributes/Resolve/Helper.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Attributes\Resolve; use ARUNOX\API\PHP; use ReflectionClass; use ARUNOX\Interfaces\Supports; trait Helper { /* ### VARIABLES ################################################ # */ protected static array $__CACHED_RESOLVES = []; /* ### PUBLIC FUNCTIONS ######################################### # */ #[PHP\Attributes\Magic\Get( fallback: TRUE, priority: 5 )] public function handleGetResolve( string $column ) { if( static::existsResolve( $column ) ) { $resolves = static::getResolve( $column ); $result = NULL; foreach( $resolves as $resolve ) { if( preg_match( '/\$\{[a-z]+\}/', $resolve ) ) { $result = preg_replace_callback( '/\$\{([a-z]+)\}/', fn( $m ) => $this->attributes[ $m[1] ], $resolve ); } else if( is_string( $resolve ) ) $result = $this->attributes[ $resolve ]; if( preg_replace( "/\s+/", "", $result ) != NULL ) return $result; } return ""; } throw new PHP\Attributes\Magic\Get\Exceptions\FallbackFailed(); } /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public static function existsResolve( string $column ) : bool { $resolves = static::getResolves(); return isset( $resolves[ $column ] ); } public static function getResolve( string $column ) : array { return static::resolveResolvesFromClass( $column ); } public static function getResolves() : array { return static::resolveResolvesFromClass(); } /* ### PRIVATE STATIC FUNCTIONS ################################# # */ private static function resolveResolvesFromClass( null|string $column = NULL ) : string|array { $reflection = new ReflectionClass( static::class ); $attributes = []; if( !isset( static::$__CACHED_RESOLVES[ static::class ] ) ) { do { foreach( $reflection->getAttributes( PHP\Attributes\Database\Attributes\Resolve::class ) as $attribute ) { $instance = $attribute->newInstance(); if( !empty( $attributes ) ) break 2; $attributes[ $instance->column ] = $instance->resolves; } $reflection = $reflection->getParentClass(); } while ($reflection); static::$__CACHED_RESOLVES[ static::class ] = $attributes; } if( $column ) { return static::$__CACHED_RESOLVES[ static::class ][ $column ] ?? ""; } return static::$__CACHED_RESOLVES[ static::class ] ?? ""; } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Attributes/Resolve/Resolve.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Attributes; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE )] class Resolve { use PHP\Attributes\Magic\Get\Helper; /* ### VARIABLES ################################################ # */ protected array $resolves = []; /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $column, ...$resolves ){ $this->resolves = (array)$resolves; } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Attributes/Helper.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Attributes; use ARUNOX\API\PHP; use ReflectionClass; use ARUNOX\Interfaces\Supports; trait Helper { /* ### VARIABLES ################################################ # */ protected static array $ATTRIBUTES = []; protected static array $__CACHED_ATTRS = []; protected static array $__CALLABLE_ATTRS = [ "toggle" => Supports\Toggle::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ #[PHP\Attributes\Magic\Call( fallback: TRUE )] public function handleAttributesCall( string $name, ...$args ) { $name = preg_split('/([[:upper:]][[:lower:]]+)/', $name, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); if( is_array( $name ) ) { $name = array_map( "strtolower", $name ); if( key_exists( $name[0], static::$__CALLABLE_ATTRS ) ) { $class = static::$__CALLABLE_ATTRS[ $name[0] ]; if( isset( $this->{$name[1]} ) ) { if( $this->{$name[1]} instanceof $class ) { if( method_exists( $this->{$name[1]}, "setParent" ) ) { $this->{$name[1]}->setParent( $this ); } return $this->{$name[1]}->{$name[0]}( ...$args ); } } } } throw new PHP\Attributes\Magic\Call\Exceptions\FallbackFailed(); } /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public static function existsAttribute( string $name ) : bool { $attrs = static::getAttributes(); return isset( $attrs[ $name ] ); } public static function getAttribute( string $name ) : mixed { $attrs = static::getAttributes(); return $attrs[ $name ] ?? NULL; } public static function getAttributes() : array { $class = static::class; if( !isset( static::$__CACHED_ATTRS[ $class ] ) ) { $attrs = static::resolveAttributesFromClass(); $attrs = static::getMergedAttributes( $attrs ); static::$__CACHED_ATTRS[ $class ] = $attrs; } return static::$__CACHED_ATTRS[ $class ]; } /* ### PRIVATE STATIC FUNCTIONS ################################# # */ private static function getMergedAttributes( null|array $defaults = []) : array { $result = $defaults; $class = static::class; do { if( property_exists( $class, "ATTRIBUTES" ) ) { $ref = new ReflectionClass( $class ); if( $ref->hasProperty("ATTRIBUTES") ) { $prop = $ref->getProperty("ATTRIBUTES"); if( $prop->isStatic() ) { $prop->setAccessible( TRUE ); $attrs = $prop->getValue(); if( is_array( $attrs ) ) { $result = array_merge( $attrs, $result ); } } } } } while( $class = get_parent_class( $class ) ); return $result; } private static function resolveAttributesFromClass() : array { $ref = new ReflectionClass( static::class ); $result = []; foreach( $ref->getAttributes( PHP\Attributes\Database\Attributes::class ) as $attr ) { $inst = $attr->newInstance(); $result[ $inst->column ] = $inst->class; } return $result; } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Definitions/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Definitions; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS )] class Model extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public function getModelClass() : string|bool { return $this->class; } public function callModelClass( string $method, ...$args ) { return $this->getModelClass()::{$method}( ...$args ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $class ){ parent::__construct( $class ); } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Definitions/HashID.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Definitions; use Attribute; use ARUNOX\API\PHP; use Hashids\Hashids; use ARUNOX\Core\Hooks; #[Attribute( Attribute::TARGET_CLASS )] class HashID extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ /* ### PUBLIC FUNCTIONS ######################################### # */ public function getHashIDPrefix() : string { return $this->prefix; } public function getHashID( int $primary ) : string { $prefix = $this->getHashIDPrefix() ?? $this->getTable(); $hashids = new Hashids( $this->getTable(), 16 ); $numbers = [ $primary ]; $numbers = Hooks::filterWithNames( "model::hashids", $this->getTable(), $numbers, $this->getTable() ); $encoded = $hashids->encode( $numbers ); $hashid = "{$this->prefix}_{$encoded}"; return $hashid; } public function resolveHashID( string $hashid, null|int $index = 0 ) : int|bool|array { $prefix = $this->getHashIDPrefix() ?? $this->getTable(); $hashid = explode( "_", $hashid ); if( $hashid[0] !== $prefix ) return FALSE; $sqids = new Hashids( $this->getTable(), 16 ); $decoded = $sqids->decode( $hashid[1] ); if( !$decoded ) return FALSE; return $index === NULL ? $decoded : $decoded[ $index ]; } public function resolveHashIDPrefix( string $hashid, null|string $column = NULL ) { $split = explode( "_", $hashid ); $class = array_search( $split[0], $this->getCacheAll() ); if( !$class ) return NULL; $data = $class::get( $hashid ); if( $column ) return $data->{$column} ?? NULL; return $data; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ private function getTable() : string { return $this->getParentClass()::getTable(); } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $prefix ){ parent::__construct( $prefix ); } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Definitions/Table.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Definitions; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS )] class Table extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ /* ### PUBLIC FUNCTIONS ######################################### # */ public function getTable( null|string $suffix = NULL ) { return implode( "_", array_filter( [ $this->table, $suffix ] ) ); } public function resolveTable( string $table ) { $class = array_search( $table, $this->getCacheAll() ); if( !$class ) return NULL; return $class; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $table, ){ parent::__construct( $table ); } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Definitions/Entity.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Definitions; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS )] class Entity extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public function getEntityClass() : string|bool { return $this->class; } public function callEntityClass( string $method, ...$args ) { return $this->getEntityClass()::{$method}( ...$args ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $class ){ parent::__construct( $class ); } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Definitions/Origin.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Definitions; use Attribute; use ARUNOX\API\PHP; use ARUNOX\Autoloader; #[Attribute( Attribute::TARGET_CLASS )] class Origin extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public function getOriginClass() : string|bool { return $this->class; } public function callOriginClass( string $method, ...$args ) { return $this->getOriginClass()::{$method}( ...$args ); } public function getControllerClass() { return Autoloader::find( $this->getNamespace(), "controller" ); } public function callControllerClass( string $method, ...$args ) { return $this->getControllerClass()::{$method}( ...$args ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $class ){ parent::__construct( $class ); } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Options/Label.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Options; use Attribute; use ARUNOX\API\PHP; #[Attribute( Attribute::TARGET_CLASS | Attribute::TARGET_CLASS_CONSTANT )] class Label extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ protected static null|string $__DEFAULT = "getSingular"; /* ### PUNLIC FUNCTIONS ######################################### # */ public function getLabel() : array { return [ "singular" => $this->singular, "plural" => $this->plural, "group" => $this->group, ]; } public function getSingular( null|string $label = NULL, ...$tokens ) : string { return $this->getLabelSingular( $label, ...$tokens ); } public function getLabelSingular( null|string $label = NULL, ...$tokens ) : string { return $this->resolveLabel( "singular", $label, "Entry", ...$tokens ); } public function getPlural( null|string $label = NULL, ...$tokens ) : string { return $this->getLabelPlural( $label, ...$tokens ); } public function getLabelPlural( null|string $label = NULL, ...$tokens ) : string { return $this->resolveLabel( "plural", $label, "Entries", ...$tokens ); } public function getLabelGroup( null|string $label = NULL, ...$tokens ) : string { return $this->resolveLabel( "group", $label, "Overview", ...$tokens ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ private function resolveLabel( null|string $column = NULL, null|string $label = NULL, null|string $fallback = NULL, ...$tokens ) : string|array { if( $column ) { if( !$label ) return __( $this->getLabel()[ $column ] ?? $fallback ); return __( $label, $this->getLabel()[ $column ] ?? $fallback, ...$tokens ); } else return $this->getLabel() ?? []; } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( protected string $singular, protected null|string $plural = NULL, protected null|string $group = NULL ){ if( !$plural ) $this->plural = $singular; if( !$group ) $this->group = $this->plural; } } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Options/Color.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Options; use Attribute; use ARUNOX\API\PHP; use ARUNOX\Plugins\REST; #[Attribute( Attribute::TARGET_CLASS | Attribute::TARGET_CLASS_CONSTANT )] class Color extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ protected static null|string $__DEFAULT = "getColor"; /* ### PUBLIC FUNCTIONS ######################################### # */ public function getColor() { return $this->CONFIG; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Options/Toggle.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Options; use Attribute; use ARUNOX\API\PHP; use ARUNOX\Plugins\REST; #[Attribute( Attribute::TARGET_CLASS_CONSTANT )] class Toggle extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ protected static null|string $__DEFAULT = "getToggle"; /* ### PUBLIC FUNCTIONS ######################################### # */ public function getToggle() { return $this->CONFIG; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: library/ARUNOX/API/PHP/Attributes/Database/Options/Icon.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Attributes\Database\Options; use Attribute; use ARUNOX\API\PHP; use ARUNOX\Plugins\REST; #[Attribute( Attribute::TARGET_CLASS | Attribute::TARGET_CLASS_CONSTANT )] class Icon extends PHP\Attributes\Attribute { /* ### VARIABLES ################################################ # */ protected static null|string $__DEFAULT = "getIcon"; /* ### PUBLIC FUNCTIONS ######################################### # */ public function getIcon() { return $this->CONFIG; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ }