From 774985582192906af3f0e1d6b937f404cea844ab Mon Sep 17 00:00:00 2001 From: Elias Kleppinger Date: Thu, 7 Nov 2024 19:05:27 +0100 Subject: [PATCH] CLI implementiert --- .gitignore | 5 +- bin/versa | 2 - platform/bin/versa | 4 ++ platform/build/.gitkeep | 0 platform/composer.json | 10 +++- .../Development/CompilePlatformCommand.php | 39 +++++++++++++ .../Commands/Module/CompileModuleCommand.php | 30 ++++++++++ .../Commands/Server/StartServerCommand.php | 35 ++++++++++++ platform/src/Console/VersaCLI.php | 56 +++++++++++++++++++ platform/src/Logging/Log.php | 28 ++++++++++ platform/src/Server/VersaServer.php | 34 +++++++++++ 11 files changed, 238 insertions(+), 5 deletions(-) delete mode 100644 bin/versa create mode 100644 platform/bin/versa create mode 100644 platform/build/.gitkeep create mode 100644 platform/src/Console/Commands/Development/CompilePlatformCommand.php create mode 100644 platform/src/Console/Commands/Module/CompileModuleCommand.php create mode 100644 platform/src/Console/Commands/Server/StartServerCommand.php create mode 100644 platform/src/Console/VersaCLI.php create mode 100644 platform/src/Logging/Log.php create mode 100644 platform/src/Server/VersaServer.php diff --git a/.gitignore b/.gitignore index a725465..2b85a1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -vendor/ \ No newline at end of file +vendor/ +composer.lock +.idea/ +*.phar \ No newline at end of file diff --git a/bin/versa b/bin/versa deleted file mode 100644 index a4abe2d..0000000 --- a/bin/versa +++ /dev/null @@ -1,2 +0,0 @@ -run(); \ No newline at end of file diff --git a/platform/build/.gitkeep b/platform/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/platform/composer.json b/platform/composer.json index 1c2c580..df3ac1f 100644 --- a/platform/composer.json +++ b/platform/composer.json @@ -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" + } } diff --git a/platform/src/Console/Commands/Development/CompilePlatformCommand.php b/platform/src/Console/Commands/Development/CompilePlatformCommand.php new file mode 100644 index 0000000..aa6269c --- /dev/null +++ b/platform/src/Console/Commands/Development/CompilePlatformCommand.php @@ -0,0 +1,39 @@ +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; + } + +} \ No newline at end of file diff --git a/platform/src/Console/Commands/Module/CompileModuleCommand.php b/platform/src/Console/Commands/Module/CompileModuleCommand.php new file mode 100644 index 0000000..70a46a9 --- /dev/null +++ b/platform/src/Console/Commands/Module/CompileModuleCommand.php @@ -0,0 +1,30 @@ +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; + } + +} \ No newline at end of file diff --git a/platform/src/Console/Commands/Server/StartServerCommand.php b/platform/src/Console/Commands/Server/StartServerCommand.php new file mode 100644 index 0000000..a3e844a --- /dev/null +++ b/platform/src/Console/Commands/Server/StartServerCommand.php @@ -0,0 +1,35 @@ +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; + } + +} \ No newline at end of file diff --git a/platform/src/Console/VersaCLI.php b/platform/src/Console/VersaCLI.php new file mode 100644 index 0000000..fd996d5 --- /dev/null +++ b/platform/src/Console/VersaCLI.php @@ -0,0 +1,56 @@ +application = new ConsoleApplication(); + + $this->application->addCommands([ + new CompilePlatformCommand(), + new CompileModuleCommand(), + new StartServerCommand() + ]); + } + + public function run(): void + { + + // Output pink text to stdout using fwrite + + $logo = <<application->run(); + } + + + +} \ No newline at end of file diff --git a/platform/src/Logging/Log.php b/platform/src/Logging/Log.php new file mode 100644 index 0000000..7b72a0b --- /dev/null +++ b/platform/src/Logging/Log.php @@ -0,0 +1,28 @@ +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); + } +} \ No newline at end of file diff --git a/platform/src/Server/VersaServer.php b/platform/src/Server/VersaServer.php new file mode 100644 index 0000000..1cbef46 --- /dev/null +++ b/platform/src/Server/VersaServer.php @@ -0,0 +1,34 @@ +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}"); + } + +} \ No newline at end of file