/** Datei: library/ARUNOX/API/PHP/Token/T_DOC_COMMENT.php **/ * @copyright 2024 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Token; use stdClass; use ARUNOX\API\PHP; class T_DOC_COMMENT extends PHP\Token { /* ### VARIABLES ################################################ # */ protected static $AUTODETECT = [ "name" => "0", "description" => "1+", ], $HEADER = [ "name" => "Plugin Name", "description" => "Description", ], $PHPDOC = [ "author" => "@author", "ignore" => "@ignore", "preload" => "@preload", "copyright" => "@copyright", "dependencies" => "@dependencies", "version" => "@version", ], $PHPDOC_MULTI = [ "hooks" => "@hook", "since" => "@since", ]; protected $data = NULL; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### PROTECTED FUNCTIONS ###################################### # */ protected function construct() { $this->data = new stdClass(); preg_match_all( "/\*[*\s]+(.*)/", $this->text, $comments ); $comments = array_filter( $comments[1] ); $autodetect = array_reverse( static::$AUTODETECT ); foreach( $comments as $index => $comment ) { foreach( static::$HEADER as $name => $regex ) { $regex = preg_quote( $regex ) . ":?\s+(.*)"; if( preg_match( "/{$regex}/", $comment, $header ) ) { $this->data->{$name} = trim( $header[1] ); continue 2; } } foreach( static::$PHPDOC as $name => $regex ) { $regex = preg_quote( $regex ) . ":?\s+(.*)"; if( preg_match( "/{$regex}/", $comment, $header ) ) { $this->data->{$name} = trim( $header[1] ); continue 2; } } foreach( static::$PHPDOC_MULTI as $name => $regex ) { $regex = preg_quote( $regex ) . ":?\s+(.*)"; if( preg_match( "/{$regex}/", $comment, $header ) ) { $this->data->{$name}[] = trim( $header[1] ); continue 2; } } if( preg_match( "/@([a-zA-Z0-9]+)(-([a-zA-Z0-9]+))?:?\s+(.*)/", $comment, $matches ) ) { $name = $matches[1]; $subname = $matches[3]; $value = $matches[4]; if( !$this->parse( $name, $value ) ) { if( $subname ) $this->data->{$name}[ $subname ] = trim( $value ); else $this->data->{$name} = trim( $value ); } continue; } foreach( $autodetect as $name => $line ) { preg_match( "/(\d+)(\+?)/", $line, $line ); if( $line[1] == $index ) { $this->data->{$name} = trim( $comment ); continue 2; } if( !$line[2] ) continue; if( $line[1] < $index ) { if( is_string( $this->data->{$name} ) ) { $this->data->{$name} = (array)trim( $this->data->{$name} ); } if( is_array( $this->data->{$name} ) ) { $this->data->{$name}[] = trim( $comment ); } $this->data->{$name} = implode( "; ", $this->data->{$name} ); } } } } /* ### PRIVATE FUNCTIONS ######################################## # */ private function parse( string $name, string $value ) { if( method_exists( $this, "parse{$name}") ) { return $this->{"parse{$name}"}( $value ); } return FALSE; } private function parseParam( string $value ) { if( !property_exists( $this->data, "params" ) ) $this->data->params = []; preg_match( "/([a-z|]+)\s+(\\\$[a-zA-Z0-9_]+)\s+(.*)\s*/", $value, $param ); return $this->data->params[ $param[2] ] = "({$param[1]}) {$param[3]}"; } /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: library/ARUNOX/API/PHP/Token/T_USE.php **/ * @copyright 2024 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP\Token; use stdClass; use ARUNOX\API\PHP; class T_USE extends PHP\Token { /* ### VARIABLES ################################################ # */ protected $row = NULL; protected $nextLine = NULL; /* ### PUBLIC FUNCTIONS ######################################### # */ public function __toString() { return $this->text . implode( "", $this->row ); } /* ### PROTECTED FUNCTIONS ###################################### # */ protected function construct( array $tokens, int $index ) { $row = array_slice( $tokens, $index ); $search = array_column( $row, "text" ); $end = array_search( ";", $search ); $this->row = array_slice( $row, 1, ++$end ); $this->nextLine = $row[ $end ]->line; } /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: library/ARUNOX/API/PHP/Token/Token.php **/ * @copyright 2024 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\PHP; #[\AllowDynamicProperties] class Token { /* ### VARIABLES ################################################ # */ protected $id = NULL, $pos = NULL, $line = NULL, $text = NULL, $name = NULL; /* ### PUBLIC FUNCTIONS ######################################### # */ public function getArgs() { return $this->ARGS ?? NULL; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ private function getReflectedValue( $name ) { $reflection = new \ReflectionClass( $this ); $property = $reflection->getProperty( $name ); return $property->getValue( $this ); } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( $token, ...$args ) { $this->id = $token->id; $this->pos = $token->pos; $this->text = $token->text; $this->line = $token->line; $this->name = token_name( $this->id ); if( method_exists( $this, "construct" ) ) $this->construct( ...$args ); } public function &__get( string $name ) { $function = "get" . ucfirst( $name ); if( method_exists( $this, $function ) ) return $this->{$function}(); if( property_exists( $this, $name ) ) return $this->getReflectedValue( $name ); if( method_exists( $this, $name ) ) return $this->{$name}(); if( isset( $this->ARGS[$name] ) ) return $this->ARGS[$name]; if( isset( $this->NODES[$name] ) ) return $this->NODES[$name]; if( $this instanceof \Iterator ) return $this->values()[ $name ] ?? NULL; return NULL; } }