CLI implementiert
This commit is contained in:
parent
e63c635800
commit
7749855821
5
.gitignore
vendored
5
.gitignore
vendored
@ -1 +1,4 @@
|
||||
vendor/
|
||||
vendor/
|
||||
composer.lock
|
||||
.idea/
|
||||
*.phar
|
||||
4
platform/bin/versa
Normal file
4
platform/bin/versa
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/../vendor/autoload.php";
|
||||
|
||||
(new \VersaDigitale\Platform\Console\VersaCLI())->run();
|
||||
0
platform/build/.gitkeep
Normal file
0
platform/build/.gitkeep
Normal file
@ -3,9 +3,10 @@
|
||||
"description": "Anwendungsserver der modularen versa digitale Anwendungsplatform",
|
||||
"type": "platform",
|
||||
"license": "MIT",
|
||||
"version": "1.0",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Versa\\Platform\\": "src/"
|
||||
"VersaDigitale\\Platform\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
@ -14,5 +15,10 @@
|
||||
"email": "e.kleppinger@buero-digitale.de"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
"require": {
|
||||
"symfony/console": "^7.1",
|
||||
"react/http": "^3@dev",
|
||||
"react/async": "^3@dev",
|
||||
"secondtruth/phar-compiler": "^1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace VersaDigitale\Platform\Console\Commands\Development;
|
||||
|
||||
use Secondtruth\Compiler\Compiler;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'dev:compile')]
|
||||
class CompilePlatformCommand extends Command
|
||||
{
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Kompliliert die Platform und erstellt die .phar Datei');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// Deine Logik für den Compiler
|
||||
$output->writeln('Starte den Compiler...');
|
||||
|
||||
$compiler = new Compiler(__DIR__ . "/../../../../");
|
||||
|
||||
$compiler->addIndexFile("bin/versa");
|
||||
$compiler->addFile("composer.json");
|
||||
$compiler->addDirectory("src", '!*.php');
|
||||
$compiler->addDirectory("vendor");
|
||||
|
||||
$compiler->compile("build/versa.phar");
|
||||
|
||||
$output->writeln('Die .phar Datei wurde erfolgreich erstellt.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace VersaDigitale\Platform\Console\Commands\Module;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: "module:compile")]
|
||||
class CompileModuleCommand extends Command
|
||||
{
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Kompliliert ein spezifisches Modul');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// Deine Logik für den Compiler
|
||||
$output->writeln('Starte den Compiler...');
|
||||
|
||||
|
||||
$output->writeln('Die .phar Datei wurde erfolgreich erstellt.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
35
platform/src/Console/Commands/Server/StartServerCommand.php
Normal file
35
platform/src/Console/Commands/Server/StartServerCommand.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace VersaDigitale\Platform\Console\Commands\Server;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use VersaDigitale\Platform\Logging\Log;
|
||||
use VersaDigitale\Platform\Server\VersaServer;
|
||||
|
||||
#[AsCommand(name: "server:start")]
|
||||
class StartServerCommand extends Command
|
||||
{
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Startet den Anwendungsserver.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// Deine Logik für den Compiler
|
||||
$ver = phpversion();
|
||||
Log::info("Starte den versa digitale Platformserver - powered by ReactPHP");
|
||||
$server = new VersaServer(
|
||||
host: "0.0.0.0",
|
||||
port: 8080
|
||||
);
|
||||
|
||||
$server->start();
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
56
platform/src/Console/VersaCLI.php
Normal file
56
platform/src/Console/VersaCLI.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace VersaDigitale\Platform\Console;
|
||||
|
||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
use VersaDigitale\Platform\Console\Commands\Development\CompilePlatformCommand;
|
||||
use VersaDigitale\Platform\Console\Commands\Module\CompileModuleCommand;
|
||||
use VersaDigitale\Platform\Console\Commands\Server\StartServerCommand;
|
||||
|
||||
/**
|
||||
* Class VersaCLI
|
||||
*
|
||||
* Represents a command-line interface for interacting with the versa digitale Platform.
|
||||
* This class provides utility methods for executing commands and retrieving
|
||||
* results from the versa digitale Platform.
|
||||
*
|
||||
*/
|
||||
class VersaCLI {
|
||||
|
||||
public function __construct(
|
||||
public ?ConsoleApplication $application = null
|
||||
)
|
||||
{
|
||||
$this->application = new ConsoleApplication();
|
||||
|
||||
$this->application->addCommands([
|
||||
new CompilePlatformCommand(),
|
||||
new CompileModuleCommand(),
|
||||
new StartServerCommand()
|
||||
]);
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
|
||||
// Output pink text to stdout using fwrite
|
||||
|
||||
$logo = <<<LOGO
|
||||
_ _ _ _ _
|
||||
__ _____ _ _ ___ __ _ __| (_)__ _(_) |_ __ _| |___
|
||||
\ V / -_) '_(_-</ _` | / _` | / _` | | _/ _` | / -_)
|
||||
\_/\___|_| /__/\__,_| \__,_|_\__, |_|\__\__,_|_\___|
|
||||
|___/
|
||||
\033[31mVersion 1.0 - by buero digitale GmbH\033[0m\n
|
||||
LOGO;
|
||||
|
||||
|
||||
fwrite(STDOUT, "\033[35m". $logo. "\033[0m\n\n");
|
||||
|
||||
$this->application->run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
28
platform/src/Logging/Log.php
Normal file
28
platform/src/Logging/Log.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace VersaDigitale\Platform\Logging;
|
||||
|
||||
class Log
|
||||
{
|
||||
public static function info(string $message): void
|
||||
{
|
||||
self::output($message, 'INFO', '32'); // Green
|
||||
}
|
||||
|
||||
public static function warning(string $message): void
|
||||
{
|
||||
self::output($message, 'WARNUNG', '33'); // Yellow
|
||||
}
|
||||
|
||||
public static function error(string $message): void
|
||||
{
|
||||
self::output($message, 'FEHLER', '31'); // Red
|
||||
}
|
||||
|
||||
private static function output(string $message, string $level, string $color): void
|
||||
{
|
||||
$formattedDate = (new \DateTime())->format('H:i:s - d.m.Y');
|
||||
$output = sprintf("\033[%sm[%s] [%s] %s\033[0m", $color, $formattedDate, $level, $message);
|
||||
fwrite(STDOUT, $output . PHP_EOL);
|
||||
}
|
||||
}
|
||||
34
platform/src/Server/VersaServer.php
Normal file
34
platform/src/Server/VersaServer.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace VersaDigitale\Platform\Server;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use React\Http\HttpServer;
|
||||
use React\Http\Message\Response;
|
||||
use React\Socket\SocketServer;
|
||||
use VersaDigitale\Platform\Logging\Log;
|
||||
|
||||
class VersaServer
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public string $host,
|
||||
public int $port,
|
||||
public ?SocketServer $socket = null,
|
||||
public ?HttpServer $http = null,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
public function start(): void {
|
||||
$this->http = new HttpServer(function (ServerRequestInterface $request) {
|
||||
return Response::plaintext(
|
||||
"Hello World!\n"
|
||||
);
|
||||
});
|
||||
$this->socket = new SocketServer("{$this->host}:{$this->port}");
|
||||
$this->http->listen($this->socket);
|
||||
Log::info("versa digitale Platform erreichbar unter {$this->host}:{$this->port}");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user