chore: complete update
This commit is contained in:
50
src/Framework/Console/Examples/ProgressBarExample.php
Normal file
50
src/Framework/Console/Examples/ProgressBarExample.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Framework\Console\Examples;
|
||||
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Console\ProgressBar;
|
||||
|
||||
class ProgressBarExample
|
||||
{
|
||||
#[ConsoleCommand(name: 'demo:progressbar', description: 'Zeigt eine Demonstration der Fortschrittsanzeige')]
|
||||
public function showProgressBarDemo(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
$output->writeInfo('Demonstration der Fortschrittsanzeige');
|
||||
$output->newLine();
|
||||
|
||||
// Einfache Fortschrittsanzeige
|
||||
$output->writeLine('Einfache Fortschrittsanzeige:');
|
||||
$progress = new ProgressBar($output, 10);
|
||||
$progress->start();
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
// Simuliere Arbeit
|
||||
usleep(200000);
|
||||
$progress->advance();
|
||||
}
|
||||
|
||||
$progress->finish();
|
||||
|
||||
// Fortschrittsanzeige mit angepasstem Format
|
||||
$output->writeLine('Fortschrittsanzeige mit angepasstem Format:');
|
||||
$progress = new ProgressBar($output, 5);
|
||||
$progress->setFormat('%bar% %current%/%total% [%percent%%] - %elapsed%s vergangen, %remaining%s verbleibend');
|
||||
$progress->setBarCharacters('█', '░', '█');
|
||||
$progress->start();
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
// Simuliere Arbeit
|
||||
usleep(500000);
|
||||
$progress->advance();
|
||||
}
|
||||
|
||||
$progress->finish();
|
||||
|
||||
$output->writeSuccess('Demonstration abgeschlossen!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
72
src/Framework/Console/Examples/SpinnerExample.php
Normal file
72
src/Framework/Console/Examples/SpinnerExample.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Framework\Console\Examples;
|
||||
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Console\Spinner;
|
||||
use App\Framework\Console\SpinnerStyle;
|
||||
|
||||
class SpinnerExample
|
||||
{
|
||||
#[ConsoleCommand(name: 'demo:spinner', description: 'Zeigt eine Demonstration der Spinner-Komponente')]
|
||||
public function showSpinnerDemo(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
$output->writeInfo('Demonstration der Spinner-Komponente');
|
||||
$output->newLine();
|
||||
|
||||
// Einfacher Spinner
|
||||
$spinner = new Spinner($output, 'Lade Daten...');
|
||||
$spinner->start();
|
||||
|
||||
// Simuliere Arbeit
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
usleep(100000);
|
||||
$spinner->update();
|
||||
}
|
||||
|
||||
$spinner->success('Daten erfolgreich geladen!');
|
||||
|
||||
// Spinner mit verschiedenen Stilen
|
||||
$styles = [
|
||||
SpinnerStyle::DOTS,
|
||||
SpinnerStyle::LINE,
|
||||
SpinnerStyle::BOUNCE,
|
||||
SpinnerStyle::ARROW
|
||||
];
|
||||
|
||||
foreach ($styles as $style) {
|
||||
$output->writeLine("Spinner-Stil: {$style->name}");
|
||||
$spinner = new Spinner($output, 'Verarbeite...', $style);
|
||||
$spinner->start();
|
||||
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
usleep(100000);
|
||||
|
||||
if ($i === 5) {
|
||||
$spinner->setMessage('Fast fertig...');
|
||||
}
|
||||
|
||||
$spinner->update();
|
||||
}
|
||||
|
||||
$spinner->success('Fertig!');
|
||||
}
|
||||
|
||||
// Fehlerhafter Prozess
|
||||
$spinner = new Spinner($output, 'Verbinde mit Server...');
|
||||
$spinner->start();
|
||||
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
usleep(150000);
|
||||
$spinner->update();
|
||||
}
|
||||
|
||||
$spinner->error('Verbindung fehlgeschlagen!');
|
||||
|
||||
$output->writeSuccess('Demonstration abgeschlossen!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
60
src/Framework/Console/Examples/TableExample.php
Normal file
60
src/Framework/Console/Examples/TableExample.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Console\Examples;
|
||||
|
||||
use App\Framework\Console\Components\Table;
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleColor;
|
||||
use App\Framework\Console\ConsoleFormat;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Console\ConsoleStyle;
|
||||
|
||||
final class TableExample
|
||||
{
|
||||
#[ConsoleCommand('demo:table', 'Zeigt eine Beispiel-Tabelle')]
|
||||
public function showTable(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
$output->writeLine('Beispiel für die Table-Komponente', ConsoleStyle::create(
|
||||
color: ConsoleColor::BRIGHT_WHITE,
|
||||
format: ConsoleFormat::BOLD
|
||||
));
|
||||
$output->newLine();
|
||||
|
||||
// Einfache Tabelle
|
||||
$table = new Table(
|
||||
headerStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_YELLOW, format: ConsoleFormat::BOLD),
|
||||
borderStyle: ConsoleStyle::create(color: ConsoleColor::CYAN)
|
||||
);
|
||||
|
||||
$table->setHeaders(['Name', 'Alter', 'Stadt'])
|
||||
->addRow(['Max Mustermann', '30', 'Berlin'])
|
||||
->addRow(['Anna Schmidt', '25', 'München'])
|
||||
->addRow(['Peter Weber', '35', 'Hamburg']);
|
||||
|
||||
$output->write($table->render());
|
||||
$output->newLine();
|
||||
|
||||
// Komplexere Tabelle mit Produktdaten
|
||||
$output->writeLine('Produktübersicht:', ConsoleStyle::create(color: ConsoleColor::BRIGHT_GREEN));
|
||||
|
||||
$productTable = new Table(
|
||||
headerStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_WHITE, format: ConsoleFormat::BOLD),
|
||||
rowStyle: ConsoleStyle::create(color: ConsoleColor::WHITE),
|
||||
borderStyle: ConsoleStyle::create(color: ConsoleColor::GRAY)
|
||||
);
|
||||
|
||||
$productTable->setHeaders(['Artikel-Nr.', 'Bezeichnung', 'Preis', 'Lagerbestand', 'Status'])
|
||||
->setPadding(2)
|
||||
->addRow(['A-1001', 'Tastatur Deluxe', '89,99 €', '45', 'Verfügbar'])
|
||||
->addRow(['A-1002', 'Gaming Maus Pro', '69,99 €', '12', 'Knapp'])
|
||||
->addRow(['A-1003', '4K Monitor 27"', '349,99 €', '0', 'Ausverkauft'])
|
||||
->addRow(['A-1004', 'USB-C Kabel 2m', '19,99 €', '156', 'Verfügbar'])
|
||||
->addRow(['A-1005', 'Wireless Headset', '129,99 €', '8', 'Knapp']);
|
||||
|
||||
$output->write($productTable->render());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
64
src/Framework/Console/Examples/TextBoxExample.php
Normal file
64
src/Framework/Console/Examples/TextBoxExample.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Console\Examples;
|
||||
|
||||
use App\Framework\Console\Components\TextBox;
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleColor;
|
||||
use App\Framework\Console\ConsoleFormat;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Console\ConsoleStyle;
|
||||
|
||||
final class TextBoxExample
|
||||
{
|
||||
#[ConsoleCommand('demo:textbox', 'Zeigt verschiedene TextBox-Beispiele')]
|
||||
public function showTextBox(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
$output->writeLine('Beispiele für die TextBox-Komponente', ConsoleStyle::create(
|
||||
color: ConsoleColor::BRIGHT_WHITE,
|
||||
format: ConsoleFormat::BOLD
|
||||
));
|
||||
$output->newLine();
|
||||
|
||||
// Einfache TextBox
|
||||
$infoBox = new TextBox(
|
||||
content: "Dies ist eine einfache Informationsbox.\nSie kann mehrere Zeilen enthalten und passt den Text automatisch an die Breite an.",
|
||||
width: 60,
|
||||
borderStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_BLUE),
|
||||
contentStyle: ConsoleStyle::create(color: ConsoleColor::WHITE),
|
||||
title: "Information"
|
||||
);
|
||||
|
||||
$output->write($infoBox->render());
|
||||
$output->newLine();
|
||||
|
||||
// Warnung TextBox
|
||||
$warningBox = new TextBox(
|
||||
content: "Warnung! Diese Aktion kann nicht rückgängig gemacht werden. Stellen Sie sicher, dass Sie ein Backup Ihrer Daten haben, bevor Sie fortfahren.",
|
||||
width: 70,
|
||||
padding: 2,
|
||||
borderStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_YELLOW),
|
||||
contentStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_WHITE),
|
||||
title: "⚠ Warnung"
|
||||
);
|
||||
|
||||
$output->write($warningBox->render());
|
||||
$output->newLine();
|
||||
|
||||
// Fehler TextBox
|
||||
$errorBox = new TextBox(
|
||||
content: "Fehler: Die Verbindung zur Datenbank konnte nicht hergestellt werden. Überprüfen Sie Ihre Zugangsdaten und stellen Sie sicher, dass der Datenbankserver läuft.",
|
||||
width: 80,
|
||||
padding: 1,
|
||||
borderStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_RED),
|
||||
contentStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_WHITE),
|
||||
title: "✗ Fehler"
|
||||
);
|
||||
|
||||
$output->write($errorBox->render());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
89
src/Framework/Console/Examples/TreeExample.php
Normal file
89
src/Framework/Console/Examples/TreeExample.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Console\Examples;
|
||||
|
||||
use App\Framework\Console\Components\TreeHelper;
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleColor;
|
||||
use App\Framework\Console\ConsoleFormat;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Console\ConsoleStyle;
|
||||
|
||||
final class TreeExample
|
||||
{
|
||||
#[ConsoleCommand('demo:tree', 'Zeigt ein Beispiel für die TreeHelper-Komponente')]
|
||||
public function showTreeExample(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
$output->writeLine('Beispiel für den TreeHelper', ConsoleStyle::create(
|
||||
color: ConsoleColor::BRIGHT_WHITE,
|
||||
format: ConsoleFormat::BOLD
|
||||
));
|
||||
$output->newLine();
|
||||
|
||||
// Einfaches Verzeichnisbeispiel
|
||||
$tree = new TreeHelper('Projektstruktur');
|
||||
$tree->setNodeStyle(ConsoleStyle::create(color: ConsoleColor::BRIGHT_CYAN, format: ConsoleFormat::BOLD));
|
||||
$tree->setLeafStyle(ConsoleStyle::create(color: ConsoleColor::WHITE));
|
||||
|
||||
$srcNode = $tree->addNode('src/');
|
||||
|
||||
$domainNode = $srcNode->addNode('Domain/');
|
||||
$domainNode->addNode('User/')->addLeaf('User.php')->addLeaf('UserRepository.php');
|
||||
$domainNode->addNode('Product/')->addLeaf('Product.php')->addLeaf('ProductRepository.php');
|
||||
|
||||
$frameworkNode = $srcNode->addNode('Framework/');
|
||||
$consoleNode = $frameworkNode->addNode('Console/');
|
||||
$consoleNode->addNode('Components/')
|
||||
->addLeaf('Table.php')
|
||||
->addLeaf('TextBox.php')
|
||||
->addLeaf('TreeHelper.php');
|
||||
|
||||
$consoleNode->addLeaf('ConsoleColor.php');
|
||||
$consoleNode->addLeaf('ConsoleFormat.php');
|
||||
$consoleNode->addLeaf('ConsoleOutput.php');
|
||||
|
||||
$testNode = $tree->addNode('tests/');
|
||||
$testNode->addLeaf('UserTest.php');
|
||||
$testNode->addLeaf('ProductTest.php');
|
||||
|
||||
$tree->addLeaf('composer.json');
|
||||
$tree->addLeaf('README.md');
|
||||
|
||||
$output->write($tree->render());
|
||||
$output->newLine(2);
|
||||
|
||||
// Zweites Beispiel: Kategorien
|
||||
$output->writeLine('Kategorie-Baum:', ConsoleStyle::create(color: ConsoleColor::BRIGHT_GREEN));
|
||||
|
||||
$categories = new TreeHelper();
|
||||
$categories->setNodeStyle(ConsoleStyle::create(color: ConsoleColor::BRIGHT_YELLOW, format: ConsoleFormat::BOLD));
|
||||
$categories->setLeafStyle(ConsoleStyle::create(color: ConsoleColor::BRIGHT_WHITE));
|
||||
$categories->setLineStyle(ConsoleStyle::create(color: ConsoleColor::GRAY));
|
||||
|
||||
$electronics = $categories->addNode('Elektronik');
|
||||
|
||||
$computers = $electronics->addNode('Computer & Zubehör');
|
||||
$computers->addLeaf('Laptops');
|
||||
$computers->addLeaf('Desktop-PCs');
|
||||
$peripherie = $computers->addNode('Peripheriegeräte');
|
||||
$peripherie->addLeaf('Monitore');
|
||||
$peripherie->addLeaf('Tastaturen');
|
||||
$peripherie->addLeaf('Mäuse');
|
||||
|
||||
$smartphones = $electronics->addNode('Smartphones & Zubehör');
|
||||
$smartphones->addLeaf('Handys');
|
||||
$smartphones->addLeaf('Hüllen');
|
||||
$smartphones->addLeaf('Ladegeräte');
|
||||
|
||||
$kleidung = $categories->addNode('Kleidung');
|
||||
$kleidung->addLeaf('Herren');
|
||||
$kleidung->addLeaf('Damen');
|
||||
$kleidung->addLeaf('Kinder');
|
||||
|
||||
$output->write($categories->render());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user