Commit 7cc44f02 authored by Marco Schmiedel's avatar Marco Schmiedel

beautified some scripts...

parent 345f746c
<?php <?php
namespace Ceetrox\Commands\BashColorDemoCommand;
use Illuminate\Console\Command;
use Ceetrox\Managers\TerminalManager\TerminalManager;
// This provider implements all artisan commands of sidekick and is triggered by the core provider. /*
class BashColorDemoCommand extends Command |------------------------------------------------------------------------------------------------
{ | Information
public function __construct() |------------------------------------------------------------------------------------------------
|
| This file is beautified by the command "sidekick:CodebeautifierCommand" of the ceetrox
| sidekick package.
|
| Author: Marco Schmiedel <marco.schmiedel@itmax.email>
| Date: 2021-12-20 15:08:24
|
*/
namespace Ceetrox\Commands\BashColorDemoCommand;
/*
|------------------------------------------------------------------------------------------------
| Dependencies
|------------------------------------------------------------------------------------------------
*/
use Ceetrox\Managers\TerminalManager\TerminalManager;
use Illuminate\Console\Command;
/*
|------------------------------------------------------------------------------------------------
| Class "BashColorDemoCommand"
|------------------------------------------------------------------------------------------------
*/
class BashColorDemoCommand extends Command
{ {
/*
|--------------------------------------------------------------------------------------------
| Method "__construct"
|--------------------------------------------------------------------------------------------
*/
public function __construct()
{
$this->signature = 'sidekick:BashColorDemoCommand'; $this->signature = 'sidekick:BashColorDemoCommand';
$this->description = TerminalManager::brightBlue("This command returns all available colors of the terminal manager."); $this->description = TerminalManager::brightBlue("This command returns all available colors of the terminal manager.");
parent::__construct(); parent::__construct();
} }
/*
|--------------------------------------------------------------------------------------------
| Method "handle"
|--------------------------------------------------------------------------------------------
*/
public function handle() public function handle()
{ {
$this->info( TerminalManager::demo() ); $this->info( TerminalManager::demo() );
}
} }
}
...@@ -10,7 +10,7 @@ class CodebeautifierCommand extends Command ...@@ -10,7 +10,7 @@ class CodebeautifierCommand extends Command
public function __construct() public function __construct()
{ {
$this->signature = 'sidekick:CodebeautifierCommand'; $this->signature = 'sidekick:CodebeautifierCommand {path?}';
$this->description = TerminalManager::brightBlue("This command is a php code beautifier."); $this->description = TerminalManager::brightBlue("This command is a php code beautifier.");
...@@ -20,8 +20,947 @@ class CodebeautifierCommand extends Command ...@@ -20,8 +20,947 @@ class CodebeautifierCommand extends Command
public function handle() public function handle()
{ {
$this->info( TerminalManager::demo() );
$file = $this->argument('path');
/*
|----------------------------------------------------------------------------------------
| Diese Schleife wird so lang durchgeführt, bis ein gültiges Script übergeben wird.
*/
while(!isset($fileexists))
{
# Pfad überprüfen
if(file_exists($file))
{
$fileexists = true;
}
else
{
# Eingang abfragen
$file = $this->ask('Bitte geben Sie den absoluten Pfad zum gewünschten Script ein');
}
}
# Beautifier starten
$beauty = new Beautifier();
# Dokument analysieren
$beauty -> Analyse($file);
# Dokument speichern
$beauty -> Render($file);
} }
} }
/*
|------------------------------------------------------------------------------------------------
| Klasse
|------------------------------------------------------------------------------------------------
| Der Beautifier ist eine eigenständige Klasse und könnte ggf. als Manager abstrahiert werden.
*/
class Beautifier
{
/*
|--------------------------------------------------------------------------------------------
| Klassenvariablen
|--------------------------------------------------------------------------------------------
*/
var $Content = [];
var $Classes = [];
var $Comments = [];
var $Linedeph = 1;
/*
|--------------------------------------------------------------------------------------------
| Method "Analyse"
|--------------------------------------------------------------------------------------------
| Diese Method analysiert alle Elemente aus dem Code.
*/
function Analyse($file)
{
# PHP File einlesen
$this->Content = file_get_contents($file);
# Basisparameter erfassen
$this->Basics();
# Kommentare erfassen
$this->Content = $this-> ScanComments($this->Content);
# Klassen einscannen
$this->ScanClass();
# Methodn einscannen
$this->ScanMethods();
# Rückgabe
return $this->Classes;
}
/*
|--------------------------------------------------------------------------------------------
| Method "Basics"
|--------------------------------------------------------------------------------------------
| Mit dieser Method werden die Basisparameter aus dem Code gelesen. Zum Beispiel werden die
| Dokumentation, der Namespace und die Abhänigkeiten ausgelesen.
*/
function Basics()
{
# Namespace erfassen
$preg = preg_match('/(^|\s)+namespace\s+[A-Za-z\\\]+;/', $this->Content, $matches, PREG_OFFSET_CAPTURE);
if(isset($matches[0]))
{
$this->namespace = trim(str_replace("\n", '', $matches[0][0]));
}
else
{
$this->namespace = false;
}
# Abhängigkeiten erfassen
$preg = preg_match_all('/(^|\s)+use\s+[^"\'\n]+[;]/', $this->Content, $matches, PREG_OFFSET_CAPTURE);
if(isset($matches[0]))
{
$this->relations = array();
foreach($matches[0] as $relation)
{
$this->relations[md5($relation[0])] = trim(str_replace("\n", '', $relation[0]));
}
}
else
{
$this->relations = false;
}
}
/*
|--------------------------------------------------------------------------------------------
| Method "DetectAnker"
|--------------------------------------------------------------------------------------------
| Die nachfolgende Method unterstützt "Doku" bei der Erkennung bestehender Beschreibungen.
| Die passenden Anker werden gesetzt.
*/
function DetectAnker($OldHtml, $Key)
{
# Erkennungshash erstellen
$md5 = md5($Key);
$Result = $this->SimpleFilter($OldHtml, '/(?<=('.$md5.'Start<\/ac:parameter><\/ac:structured-macro>)).+?(?=(<ac:structured-macro))/');
# Template starten
$tpl = '<ac:structured-macro ac:name="anchor" ac:schema-version="1">
<ac:parameter ac:name="">'.$md5.'Start</ac:parameter>
</ac:structured-macro>
';
# Text einsetzen
if($Result != '')
{
$tpl .= $Result;
}
else
{
$tpl .= '<ul>
<li>Unbekannt</li>
</ul>';
}
# Template stoppen
$tpl .= '<ac:structured-macro ac:name="anchor" ac:schema-version="1">
<ac:parameter ac:name="">'.$md5.'Stop</ac:parameter>
</ac:structured-macro>
';
# Rückgabe
return $tpl;
}
/*
|--------------------------------------------------------------------------------------------
| Method "GetCommentFromPregMatch"
|--------------------------------------------------------------------------------------------
| Mit dieser Method kann ein String, welcher durch ScanClass gehasht wurde,
| zurückverwandelt werden.
*/
function GetCommentFromPregMatch($pattern, $string)
{
# Pattern überprüfen
preg_match($pattern, $string, $description, PREG_OFFSET_CAPTURE);
$Result = false;
# Beschreibung aus Cache laden
if(isset($description[0][0]))
{
preg_match('/(?<=(#COMMENT-)).+(?=(-COMMENT#))/', $description[0][0], $md5, PREG_OFFSET_CAPTURE);
if(isset($md5[0][0]))
{
$Result = $this->Comments[$md5[0][0]];
}
}
# Beschreibung normalisieren
$Result = $this->Normalize($Result);
return $Result;
}
/*
|--------------------------------------------------------------------------------------------
| Method "MatchBetweenTwoPatterns"
|--------------------------------------------------------------------------------------------
| Diese Method filtert einen String, zwischen 2 Regex Patterns und gibt diesen zurück.
*/
function MatchBetweenTwoPatterns($String, $StartPattern, $StopPattern, $Debug = false)
{
# Arbeitsarray für den korrekten Ablauf
$Informationen = array();
# alle Startpattern filtern
$Start = preg_match_all($StartPattern, $String, $StartResults, PREG_OFFSET_CAPTURE);
if($Start == false)
{
return false;
}
foreach($StartResults[0] as $Result)
{
preg_match_all('/.*/s', $String, $FullResult, PREG_OFFSET_CAPTURE, $Result[1]);
$Informationen[$Result[1].'2'] = ['Offset' => $Result[1], 'Type' => 'Start', 'String' => $FullResult[0][0][0]];
}
# alle Stoppattern filtern
$Stop = preg_match_all($StopPattern, $String, $StopResults, PREG_OFFSET_CAPTURE);
if($Stop == false)
{
return false;
}
foreach($StopResults[0] as $Result)
{
preg_match_all('/.*/s', $String, $FullResult, PREG_OFFSET_CAPTURE, $Result[1]);
$Informationen[$Result[1].'1'] = ['Offset' => $Result[1], 'Type' => 'Stop', 'String' => $FullResult[0][0][0]];
}
# richtige Reihenfolge (des Offsets) einhalten
ksort($Informationen);
# Ergebnisarray anlegen
$Result = array();
# Ergebnisse rendern
foreach($Informationen as $Information)
{
# Start erkennen
if($Information['Type'] == 'Start')
{
# Puffer befüllen
$Puffer = $Information['String'];
}
# Stop erkennen
elseif(isset($Puffer))
{
# Ergebnis rendern
$Result[] = substr($Puffer, 0, (strlen( $Information['String'])*-1 ) );
# Puffer zurücksetzen
unset($Puffer);
}
}
# Rückgabe
return $Result;
}
/*
|--------------------------------------------------------------------------------------------
| Method "Normalize"
|--------------------------------------------------------------------------------------------
| Diese Method normalisiert einen String.
*/
function Normalize($string)
{
# Allman Style erstellen
$string = preg_replace('/{\s*$/m', "\n{", $string);
# leere Zeilen und Tabstops entfernen
$string = preg_replace('/^[\s\t]+[\n]*/m', '', $string);
# doppelte Leerzeichen entfernen
$string = preg_replace("#[ \t]+#", " ", $string);
# Rückgabe
return $string;
}
/*
|--------------------------------------------------------------------------------------------
| Method "Render"
|--------------------------------------------------------------------------------------------
| Mit dieser Method wird das Template gerendert. Standardmäßig wird der Output in eine
| Datei geschrieben. Mit der Variable "$fake" kann der Output aber auch als Variable zurück
| gegeben werden.
*/
function Render($file, $fake = false)
{
# Template einlesen
$this->tpl = file_get_contents(__dir__.'/Template.tpl');
# Zeitstempel in Template einsetzen
$this->tpl = str_replace('%timestasmp%', date('Y-m-d H:i:s'), $this->tpl);
# Authoor
$git = str_replace("\n",'',shell_exec("git config user.name").' <'.shell_exec("git config user.email").'>');
$this->tpl = str_replace('%author%', $git, $this->tpl);
# Namespace in Template einsetzen
if($this->namespace != false)
{
$this->tpl = str_replace('%namespace%', $this->S().$this->namespace, $this->tpl);
}
else
{
$this->tpl = str_replace("\n%namespace%", '', $this->tpl);
}
# Abhänigkeiten in Template einsetzen (wenn vorhanden)
if($this->relations != false)
{
# Abhänigkeiten nach Zeichenlänge sortieren
usort($this->relations, function($a, $b)
{
return strlen($b) - strlen($a);
});
# Implodieren aller Abhänigkeiten
$implode = implode("\n".$this->S(), $this->relations);
# implodierte Abhänigkeiten in Template einsetzen
$this->tpl = str_replace('%relations%', $this->S().$implode, $this->tpl);
}
# Abhänigkeiten aus Template löschen (wenn nicht vorhanden)
else
{
$this->tpl = str_replace("\n%relations%", '', $this->tpl);
}
# Klassen rendern und in Template einsetzen
$stream = $this->RenderClasses();
$this->tpl = str_replace("%classes%", $stream, $this->tpl);
# Rückgabe des validierten Dokuments
if($fake == true)
{
return $this->tpl;
}
# fertige Daten in physische Datei schreiben
file_put_contents($file, $this->tpl);
}
/*
|--------------------------------------------------------------------------------------------
| Method "RenderClasses"
|--------------------------------------------------------------------------------------------
| Diese Method unterstützt den Renderprozess "Render" beim durchlaufen der einzelnen
| Klassen.
*/
function RenderClasses()
{
# Informationsstream für Template erstellen
$classstream = '';
# alle Klassen durchlaufen
foreach($this->Classes as $class)
{
# Opening Tag bereinigen
$class['OpeningTag'] = preg_replace("/[\n\t\r]+/", " ", $class['OpeningTag']);
$preg = preg_match('/ (?<=class.)[A-Za-z]*/', $class['OpeningTag'], $matches, PREG_OFFSET_CAPTURE);
$classname = str_replace(" ", "",$matches[0][0]);
# Klassenkommentar hinzufügen
$classstream .= $this->WriteComment($class['Comment'], 'Class "'.$classname.'"');
# Tag öffnen
$classstream .= $this->S().$class['OpeningTag']."\n";
$classstream .= $this->S().'{'."\n";
# Klassenvariablen einfügen (sofern vorhanden)
if(!empty($class['Variables']))
{
# Zeilentiefe erhöhen
$this->Linedeph++;
# Kommentar vermerken
$classstream .= $this->WriteComment('', 'Klassenvariablen');
# Variablen implodieren und einsetzen
$classstream .= $this->S().implode("\n".$this->S(), $class['Variables']);
$classstream .= "\n\n";
# Zeilentiefe herabsetzen
$this->Linedeph--;
}
/*
|------------------------------------------------------------------------------------
| Nachfolgend wird eine SubMethod zum Rendern der einzelnen Methodn aufgerufen.
*/
$this->Linedeph++;
$classstream .= $this->RenderMethods($class['Methods']);
$this->Linedeph--;
# Tag schließen
$classstream .= $this->S().'}'."\n\n\n";
}
# Rückgabe
return $classstream;
}
/*
|--------------------------------------------------------------------------------------------
| Method "RenderMethods"
|--------------------------------------------------------------------------------------------
| Diese Method unterstützt den Renderprozess "Render" beim durchlaufen der einzelnen
| Methodn. Sie wird durch die Method "RenderClasses" aufgerufen.
*/
function RenderMethods($methods)
{
# Informationsstream für Template erstellen
$methodstream = '';
# Methodn alphabetisch ordnen
//$methods = MARR::OrderArray($methods, 'Title', SORT_ASC);
# jede Method durchlaufen
foreach($methods as $method)
{
# Kommentar zur Method einfügen
$methodstream .= "\n";
$methodstream .= $this->WriteComment($method['Comment'], 'Method "'.$method['Title'].'"');
# Mit dieser Variable wird die Einrücktiefe auf Methodninterner Ebene geprüft
$internaldeph = 0;
/*
|------------------------------------------------------------------------------------
| Mit dieser Variabele wird vermerkt, ob das letzte Element, im nachfolgenden
| Durchlauf, ein Kommentar war.
*/
$lastwascomment = false;
/*
|------------------------------------------------------------------------------------
| Jede Zeile der Method wird durch Explode getrennt und einzeln überprüft.
*/
foreach(explode("\n", $method['Body']) as $body)
{
/*
|--------------------------------------------------------------------------------
| Wird das "Close" Tag erkannt, wird die Einrücktiefe reudziert. Handelt es
| sich um die letzte Ebene (Ebene 0) wird ein weiteres Leerzeichen ergänzt.
*/
if(substr($body, 0,1) == '}')
{
$this->Linedeph--;
$internaldeph--;
if($internaldeph != 0)
{
$methodstream .= $this->S().$body."\n";
}
else
{
$methodstream .= "\n".$this->S().$body."\n";
}
}
/*
|--------------------------------------------------------------------------------
| Nachfolgend werden Kommentare erkannt und eingesetzt.
*/
elseif(substr($body, 0,8) == '#COMMENT')
{
$comment = $this->GetCommentFromPregMatch('/#.+-.+-.+#/',$body );
if($lastwascomment == true)
{
$methodstream .= $this->WriteComment( $comment );
}
else
{
$methodstream .= "\n".$this->WriteComment( $comment );
}
$lastwascomment = true;
}
/*
|--------------------------------------------------------------------------------
| Für if, foreach, while und return wird ein weiterer Zeilenumbruch
| hinzugefügt, sofern das letzte Element kein Kommentar war.
*/
elseif(
(
substr($body, 0,2) == 'if' or
substr($body, 0,7) == 'foreach' or
substr($body, 0,5) == 'while' or
substr($body, 0,6) == 'return'
)
and $lastwascomment == false
)
{
$methodstream .= "\n".$this->S().$body."\n";
}
/*
|--------------------------------------------------------------------------------
| Nachfolgend wird ganz normaler Text geschrieben, welcher zuvor nicht durch
| eine Sonderbehandlung erkannt wurde.
*/
else
{
$methodstream .= $this->S().$body."\n";
$lastwascomment = false;
}
/*
|--------------------------------------------------------------------------------
| Wir das "Open" Tag erkannt, wird die Einrücktiefe erhöht. "$lastwascomment"
| wird an dieser Stelle verwendet um, vor dem ersten Kommentar, den
| Zeilenumbruch zu vermeiden.
*/
if(substr($body, 0,1) == '{')
{
$lastwascomment = true;
$this->Linedeph++;
$internaldeph++;
}
}
$methodstream .= "\n";
}
# Rückgabe
return $methodstream;
}
/*
|--------------------------------------------------------------------------------------------
| Method "S"
|--------------------------------------------------------------------------------------------
| Diese Method ünterstützt das Script bei der aktuellen Einrücktiefe. Es gibt einen
| String mit den entsprechenden Leerzeichen zurück.
*/
function S()
{
$c = 0;
$x = '';
while ($c < $this->Linedeph*4)
{
$c++;
$x .= ' ';
}
return $x;
}
/*
|--------------------------------------------------------------------------------------------
| Method "ScanClass"
|--------------------------------------------------------------------------------------------
| Diese Method ist für das einscannen der Klasse zuständig. Mit Hilfe der Method
| "MatchBetweenTwoPatterns" wird der jeweilige Bereich zwischen Start und Stop extrahiert.
*/
function ScanClass()
{
# Start Pattern
$OpenPattern = '/[^;{}$*"]+class[^a-z\\\[(=-][^{;()[\]]+/s';
# Stop Pattern
$ClosePattern = '/([^;{$}>*$()"]+\s*class[^a-z\\[(=-])|[\s\t\n]+$/';
# Bereich extrahieren
$Classes = $this->MatchBetweenTwoPatterns($this->Content, $OpenPattern, $ClosePattern);
# erkannte Klassen verarbeiten
foreach($Classes as $Class)
{
# Text der Klasse normalisieren
$Class = $this->Normalize($Class);
/*
|------------------------------------------------------------------------------------
| Nachfolgend wird überprüft, ob es sicht tatsächlich um eine Klasse handelt.
| Wenn nicht wird das Element nicht weiter bearbeitet.
*/
$preg = preg_match('/class[^{;()[\]]+/', $Class, $matches, PREG_OFFSET_CAPTURE);
if(!isset($matches[0]))
{
continue;
}
/*
|------------------------------------------------------------------------------------
| Die Beschreibung der Klasse wird extrahiert und vermerkt.
*/
$description = $this->GetCommentFromPregMatch('/#.+-.+-.+#(?=(\n\s*class))/',$Class );
/*
|------------------------------------------------------------------------------------
| Nachfolgend wird geprüft, ob Klassenvariablen vorhanden sind. Diese werden
| später vermerkt oder auf "false" gesetzt.
*/
$preg = preg_match_all('/(public|protected|private|var)\s*\$.*\;/', $Class, $variables, PREG_OFFSET_CAPTURE);
if(isset($variables[0]))
{
$classvariables = array();
foreach($variables[0] as $relation)
{
$classvariables[md5($relation[0])] = $relation[0];
}
}
else
{
$classvariables = false;
}
# Informationen aus der Klasse speichern
$this->Classes[] = ['OpeningTag' => $matches[0][0], 'Body' => $Class, 'Comment' => $description, 'Methods' => [] , 'Variables' => $classvariables];
}
}
/*
|--------------------------------------------------------------------------------------------
| Method "ScanComments"
|--------------------------------------------------------------------------------------------
| Diese Method ist dafür zuständig, Kommentare aus der Originaldatei zu extrahieren, und
| während des Verarbeitungsprozesses in ein ein einfacherers, temporäres Format zu
| übertragen. Der Originalinhalt des Kommentaras wird in der Klasse gepuffert.
*/
function ScanComments($Content)
{
# Filter
preg_match_all('/^[\s]*(\/\/)[^\n]+|^[\s]*#.+[^\n]|(^|\s)+\/\*(.|\n)+?(?<=(\*\/))/m', $Content, $Comments, PREG_OFFSET_CAPTURE);
# alle Kommentare durchlaufen
foreach($Comments[0] as $Com)
{
/*
|------------------------------------------------------------------------------------
| Das Kommentar wird zur besseren identifizierung gehasth.
*/
$md = md5($Com[0]);
# Kommentar in den Puffer speichern
$this->Comments[$md] = $Com[0];
}
/*
|----------------------------------------------------------------------------------------
| Nachfolgend wird das Kommentar nach Zeichenlänge sortiert. Damit wird ein Bug
| verhindert, welche kleinere, gleiche Strings falsch ersetzt.
*/
usort($this->Comments, function($a, $b)
{
return strlen($b) - strlen($a);
});
/*
|----------------------------------------------------------------------------------------
| Die Kommentare werden aus dem Dokument entfernt.
*/
foreach($this->Comments as $key=>$value)
{
$Content = str_replace($value, "\n#COMMENT-".$key."-COMMENT#\n", $Content);
}
# Rückgabe
return $Content;
}
/*
|--------------------------------------------------------------------------------------------
| Method "ScanMethods"
|--------------------------------------------------------------------------------------------
| Diese Method scannt alle Methodn jeder Klasse ein und vermerkt diese.
*/
function ScanMethods()
{
# alle Klassen durchlaufen
foreach($this->Classes as $Key=>$Class)
{
# Methodn Klasse
$Methods = array();
/*
|------------------------------------------------------------------------------------
| Nachfolgend werden überreste der Klasse aus dem String entfernt, um nur nach
| Methodn suchen zu können.
*/
$ClassStart = strpos($Class['Body'] , '{')+1;
$ClassStop = strrpos($Class['Body'] , '}');
$ClassCount = strlen($Class['Body']);
$Prepared = substr($Class['Body'], $ClassStart, ($ClassCount-$ClassStart)-($ClassCount-$ClassStop)) ;
/*
|------------------------------------------------------------------------------------
| Ähnlich wie beim extrahieren der Klassen, wird bei den Methodn ein Start und
| Stoppattern definiert. Zwischen diesen regulären Ausdrücken werden die Methodn
| extrahiert.
*/
$OpenPattern = '/([^;{}]+function[^a-z\\\[(][^{;()[\]]+)/';
$ClosePattern = '/([^;{$}>\'"*]+\s*function[^a-z\\[(])|[\s\t\n]+$/';
$Results = $this->MatchBetweenTwoPatterns($Prepared, $OpenPattern, $ClosePattern);
# alle Methodn verarbeiten
foreach($Results as $Result)
{
preg_match('/(private|public|protected|static)*\s*function\s*\w+.*(?<=\))/', $Result, $opener, PREG_OFFSET_CAPTURE);
if(!isset($opener[0]))
{
continue;
}
/*
|--------------------------------------------------------------------------------
| Mit Hilfe der nachfolgenden Verschachtelung, wird der Title der Method
| extrahiert.
*/
$OpenerArray = str_replace(' ' , '', explode( '(',str_replace(')','',$opener[0][0])));
$Title = substr($OpenerArray[0], (strrpos($OpenerArray[0],'function')+8) );
$description = $this->GetCommentFromPregMatch('/#.+-.+-.+#(?=(\n(public|protected|private|static|\s)*function))/',$Result );
/*
|--------------------------------------------------------------------------------
| Mit diesem Befehl wird das Kommentar vor der Funktion entfernt
| (Duplettenschutz).
*/
$Result = preg_replace('/(#COMMENT.+\s*(?=(\n.*function[^a-z\\[(])))/', '', $Result);
/*
|--------------------------------------------------------------------------------
| Nach mehrfacher Änderung wird der String normalisiert.
*/
$Result = $this->Normalize($Result);
/*
|--------------------------------------------------------------------------------
| Aus der Parameter Array darf nur alle, nach dem Dollerzeichen verwendet werden.
*/
$afterdollar = [];
foreach(explode(',', $OpenerArray[1]) as $dollar)
{
$afterdollar[] = preg_replace('/.+(?=(\$))/', '', $dollar);
}
# Method speichern
$Methods[] = [
'Title' => $Title,
'Parameter' => $afterdollar,
'Comment' => $description,
'Body' => $Result
];
}
# alle Methodn in der Klasse vermerken
$this->Classes[$Key]['Methods'] = $Methods;
}
}
/*
|--------------------------------------------------------------------------------------------
| Method "SimpleFilter"
|--------------------------------------------------------------------------------------------
| Diese Method hat die Aufgabe, Textbausteine aus einer bestehenden Dokumentation zu
| extrahieren. Zur besseren Verarbeitung werden leerzeichen entfernt.
*/
function SimpleFilter($String, $Pattern)
{
# Sonderzeichen entfernen
$String = str_replace("\n", '', $String);
# Pattern
preg_match($Pattern, $String, $Extract);
# Fallback
if(!isset($Extract[0]))
{
return '';
}
# Anfang bereinigen
if(substr($Extract[0], 0,4) == '</p>')
{
$Extract[0] = substr($Extract[0], 4);
}
# Ende bereinigen
if(substr($Extract[0], -3) == '<p>')
{
$Extract[0] = substr($Extract[0], 0, -3);
}
# Rückgabe
return $Extract[0];
}
/*
|--------------------------------------------------------------------------------------------
| Method "WriteComment"
|--------------------------------------------------------------------------------------------
| Diese Method unterstützt beim erstellen, eines korrekt formatierten Kommentars. Mit der
| Variable "$fake" wird nur der Text des Kommentars zurück gegeben.
*/
function WriteComment($comment, $title = null, $fake = false)
{
/*
|----------------------------------------------------------------------------------------
| Die nachfolgende Variable startet den String für ein neues Kommentar.
*/
$k = '';
/*
|----------------------------------------------------------------------------------------
| nachfolgend wird das übertagene Kommentar bereinigt und normalisiert.
*/
$comment = preg_replace('/[^a-zA-Z:,.0-9_=$+!? äÄüÜÖöß"\'()]/', '', $comment);
$comment = $this->Normalize($comment);
/*
|----------------------------------------------------------------------------------------
| Der Beautifier verwendet für z.B. Klassen und Methodn bestimmte Keywords. Diese
| werden hier gefiltert um bei mehrfachen Renderprozessen keine Dupletten zu bilden.
*/
if(strpos($comment, $title) === 0)
{
$comment = substr($comment, strlen($title));
$comment = $this->Normalize($comment);
}
/*
|----------------------------------------------------------------------------------------
| Das Kommentar wird im Fakemodus ohne Formatierung zurück gegeben.
*/
if($fake == true)
{
return $comment;
}
/*
|----------------------------------------------------------------------------------------
| Das Kommentar wird auf mehrere Zeilen aufgeteilt (sofern mehrere Zeilen vorhanden
| sind).
*/
$comment = wordwrap($comment,98 - (strlen($this->S())));
$comment = explode("\n", $comment);
/*
|----------------------------------------------------------------------------------------
| Falls das Kommentar mehr als eine Zeile besitzt oder ein Title übergeben wurde, wird
| ein großes Kommentar verwendet. Andernfalls wird nur ein einzeiliges Kommentar
| eingesetzt.
*/
if($title != null or isset($comment[1]) or strstr($comment[0], '.'))
{
$large = true;
}
else
{
$large = false;
}
# großes Kommentar verarbeiten
if($large == true )
{
$k = $this->S().'/*'."\n";
if($title != null)
{
$k .= $this->S().'|'.str_repeat('-',100 - (strlen($this->S())) )."\n";
$k .= $this->S().'| '.$title."\n";
}
$k .= $this->S().'|'.str_repeat('-',100 - (strlen($this->S())) )."\n";
foreach($comment as $com)
{
if(!empty($com))
{
$k .= $this->S().'| '.$com."\n";
}
}
$k .= $this->S().'*/'."\n";
}
# kleines Kommentar verarbeiten
else
{
$k .= $this->S().'# '.$comment[0]."\n";
}
# Rückgabe
return $k;
}
}
<?php
/*
|------------------------------------------------------------------------------------------------
| Information
|------------------------------------------------------------------------------------------------
|
| This file is beautified by the command "sidekick:CodebeautifierCommand" of the ceetrox
| sidekick package.
|
| Author: %author%
| Date: %timestasmp%
|
*/
%namespace%
/*
|------------------------------------------------------------------------------------------------
| Dependencies
|------------------------------------------------------------------------------------------------
*/
%relations%
%classes%
<?php <?php
/* ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ *\
|◦ Namespaces /*
\* ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ */ |------------------------------------------------------------------------------------------------
| Information
|------------------------------------------------------------------------------------------------
|
| This file is beautified by the command "sidekick:CodebeautifierCommand" of the ceetrox
| sidekick package.
|
| Author: Marco Schmiedel <marco.schmiedel@itmax.email>
| Date: 2021-12-20 15:21:14
|
*/
namespace Ceetrox\Managers\TerminalManager; namespace Ceetrox\Managers\TerminalManager;
/* ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ */ /*
|------------------------------------------------------------------------------------------------
| Dependencies
|------------------------------------------------------------------------------------------------
*/
/*
|------------------------------------------------------------------------------------------------
| Class "TerminalManager"
|------------------------------------------------------------------------------------------------
*/
class TerminalManager class TerminalManager
{ {
/*
|--------------------------------------------------------------------------------------------
| Method "brightBlue"
|--------------------------------------------------------------------------------------------
*/
static function brightBlue($text) static function brightBlue($text)
{ {
return TerminalManager::brightColor($text, 33); return TerminalManager::brightColor($text, 33);
} }
/*
|--------------------------------------------------------------------------------------------
| Method "darkColor"
|--------------------------------------------------------------------------------------------
| This method generates the dark color palette.
*/
static function darkColor($text, $color) static function darkColor($text, $color)
{ {
return "\e[0m"."\e[48;5;234m"."\e[38;5;".$color."m". $text . "\e[0m" ; return "\e[0m"."\e[48;5;234m"."\e[38;5;".$color."m". $text . "\e[0m" ;
} }
/*
|--------------------------------------------------------------------------------------------
| Method "brightColor"
|--------------------------------------------------------------------------------------------
| This method generates the bright color palette.
*/
static function brightColor($text, $color) static function brightColor($text, $color)
{ {
return "\e[0m"."\e[38;5;16m"."\e[48;5;".$color."m". $text . "\e[0m" ; return "\e[0m"."\e[38;5;16m"."\e[48;5;".$color."m". $text . "\e[0m" ;
} }
/*
|--------------------------------------------------------------------------------------------
| Method "demo"
|--------------------------------------------------------------------------------------------
| This method generates all available terminal colors for a demo output.
*/
static function demo() static function demo()
{ {
/*
|----------------------------------------------------------------------------------------
| Create an empty string for all upcoming colors...
*/
$text = "\n"; $text = "\n";
/*
|----------------------------------------------------------------------------------------
| Create counter value...
*/
$i1=16; $i1=16;
/*
|----------------------------------------------------------------------------------------
| Loop counter value within the color range...
*/
while ( $i1 < 52 ) while ( $i1 < 52 )
{ {
/*
|------------------------------------------------------------------------------------
| Calculate 7 columns per line...
*/
$i1=$i1;
$i2=$i1+36; $i2=$i1+36;
$i3=$i2+36; $i3=$i2+36;
$i4=$i3+36; $i4=$i3+36;
$i5=$i4+36; $i5=$i4+36;
$i6=$i5+36; $i6=$i5+36;
$i7=$i6+36; $i7=$i6+36;
if ( $i7 > 250 ) { $i7 = $i7-251; } if ( $i7 > 250 ) { $i7 = $i7-251; }
/*
|------------------------------------------------------------------------------------
| Calculate for bright and dark...
*/
$text .= TerminalManager::darkColor(" D".str_pad($i1, 3, "0", STR_PAD_LEFT)." ",$i1); $text .= TerminalManager::darkColor(" D".str_pad($i1, 3, "0", STR_PAD_LEFT)." ",$i1);
$text .= TerminalManager::darkColor(" D".str_pad($i2, 3, "0", STR_PAD_LEFT)." ",$i2); $text .= TerminalManager::darkColor(" D".str_pad($i2, 3, "0", STR_PAD_LEFT)." ",$i2);
$text .= TerminalManager::darkColor(" D".str_pad($i3, 3, "0", STR_PAD_LEFT)." ",$i3); $text .= TerminalManager::darkColor(" D".str_pad($i3, 3, "0", STR_PAD_LEFT)." ",$i3);
...@@ -52,7 +120,6 @@ ...@@ -52,7 +120,6 @@
$text .= TerminalManager::darkColor(" D".str_pad($i5, 3, "0", STR_PAD_LEFT)." ",$i5); $text .= TerminalManager::darkColor(" D".str_pad($i5, 3, "0", STR_PAD_LEFT)." ",$i5);
$text .= TerminalManager::darkColor(" D".str_pad($i6, 3, "0", STR_PAD_LEFT)." ",$i6); $text .= TerminalManager::darkColor(" D".str_pad($i6, 3, "0", STR_PAD_LEFT)." ",$i6);
$text .= TerminalManager::darkColor(" D".str_pad($i7, 3, "0", STR_PAD_LEFT)." ",$i7); $text .= TerminalManager::darkColor(" D".str_pad($i7, 3, "0", STR_PAD_LEFT)." ",$i7);
$text .= TerminalManager::brightColor(" B".str_pad($i1, 3, "0", STR_PAD_LEFT)." ",$i1); $text .= TerminalManager::brightColor(" B".str_pad($i1, 3, "0", STR_PAD_LEFT)." ",$i1);
$text .= TerminalManager::brightColor(" B".str_pad($i2, 3, "0", STR_PAD_LEFT)." ",$i2); $text .= TerminalManager::brightColor(" B".str_pad($i2, 3, "0", STR_PAD_LEFT)." ",$i2);
$text .= TerminalManager::brightColor(" B".str_pad($i3, 3, "0", STR_PAD_LEFT)." ",$i3); $text .= TerminalManager::brightColor(" B".str_pad($i3, 3, "0", STR_PAD_LEFT)." ",$i3);
...@@ -61,25 +128,24 @@ ...@@ -61,25 +128,24 @@
$text .= TerminalManager::brightColor(" B".str_pad($i6, 3, "0", STR_PAD_LEFT)." ",$i6); $text .= TerminalManager::brightColor(" B".str_pad($i6, 3, "0", STR_PAD_LEFT)." ",$i6);
$text .= TerminalManager::brightColor(" B".str_pad($i7, 3, "0", STR_PAD_LEFT)." ",$i7); $text .= TerminalManager::brightColor(" B".str_pad($i7, 3, "0", STR_PAD_LEFT)." ",$i7);
/*
|------------------------------------------------------------------------------------
| Add linebreak...
*/
$text .= "\n"; $text .= "\n";
/*
|------------------------------------------------------------------------------------
| Add value to counter...
*/
$i1 += 1; $i1 += 1;
} }
return $text; return $text;
} }
}
}
<?php <?php
namespace Ceetrox\Providers\CommandServiceProvider;
use Illuminate\Support\ServiceProvider;
// This provider implements all artisan commands of sidekick and is triggered by the core provider. /*
class CommandServiceProvider extends ServiceProvider |------------------------------------------------------------------------------------------------
{ | Information
|------------------------------------------------------------------------------------------------
|
| This file is beautified by the command "sidekick:CodebeautifierCommand" of the ceetrox
| sidekick package.
|
| Author: Marco Schmiedel <marco.schmiedel@itmax.email>
| Date: 2021-12-20 15:22:21
|
*/
namespace Ceetrox\Providers\CommandServiceProvider;
/*
|------------------------------------------------------------------------------------------------
| Dependencies
|------------------------------------------------------------------------------------------------
*/
use Illuminate\Support\ServiceProvider;
/*
|------------------------------------------------------------------------------------------------
| Class "CommandServiceProvider"
|------------------------------------------------------------------------------------------------
| This provider implements all artisan commands of sidekick and is triggered by the core
| provider.
*/
class CommandServiceProvider extends ServiceProvider
{
/*
|--------------------------------------------------------------------------------------------
| Method "register"
|--------------------------------------------------------------------------------------------
*/
public function register() public function register()
{ {
$this->commands('Ceetrox\Commands\CodebeautifierCommand\CodebeautifierCommand'); $this->commands('Ceetrox\Commands\CodebeautifierCommand\CodebeautifierCommand');
$this->commands('Ceetrox\Commands\BashColorDemoCommand\BashColorDemoCommand'); $this->commands('Ceetrox\Commands\BashColorDemoCommand\BashColorDemoCommand');
}
} }
}
<?php <?php
namespace Ceetrox\Providers;
use Illuminate\Support\ServiceProvider;
use Ceetrox\Providers\CommandServiceProvider\CommandServiceProvider;
/*
|------------------------------------------------------------------------------------------------
| Information
|------------------------------------------------------------------------------------------------
|
| This file is beautified by the command "sidekick:CodebeautifierCommand" of the ceetrox
| sidekick package.
|
| Author: Marco Schmiedel <marco.schmiedel@itmax.email>
| Date: 2021-12-20 15:21:50
|
*/
namespace Ceetrox\Providers;
// This provider implements the core system of sidekick.
class CoreServiceProvider extends ServiceProvider /*
{ |------------------------------------------------------------------------------------------------
| Dependencies
|------------------------------------------------------------------------------------------------
*/
use Ceetrox\Providers\CommandServiceProvider\CommandServiceProvider;
use Illuminate\Support\ServiceProvider;
/*
|------------------------------------------------------------------------------------------------
| Class "CoreServiceProvider"
|------------------------------------------------------------------------------------------------
| This provider implements the core system of sidekick.
*/
class CoreServiceProvider extends ServiceProvider
{
/*
|--------------------------------------------------------------------------------------------
| Method "register"
|--------------------------------------------------------------------------------------------
*/
public function register() public function register()
{ {
// Register the artisan command service provider. /*
|----------------------------------------------------------------------------------------
| Register the artisan command service provider.
*/
app()->register( new CommandServiceProvider( app() ) ); app()->register( new CommandServiceProvider( app() ) );
} }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment