From a9ed6ca916dc9751aef05e60afa4a9f87b64c884 Mon Sep 17 00:00:00 2001 From: Elias Kleppinger Date: Thu, 7 Nov 2024 21:35:54 +0100 Subject: [PATCH] Inital upload --- .gitignore | 4 ++ bin/versa | 4 ++ build/.gitkeep | 0 composer.json | 24 ++++++++ .../Development/CompilePlatformCommand.php | 39 +++++++++++++ .../Commands/Module/CompileModuleCommand.php | 30 ++++++++++ .../Commands/Server/StartServerCommand.php | 35 ++++++++++++ src/Console/VersaCLI.php | 56 +++++++++++++++++++ src/Logging/Log.php | 28 ++++++++++ src/Server/VersaServer.php | 34 +++++++++++ 10 files changed, 254 insertions(+) create mode 100644 .gitignore create mode 100644 bin/versa create mode 100644 build/.gitkeep create mode 100644 composer.json create mode 100644 src/Console/Commands/Development/CompilePlatformCommand.php create mode 100644 src/Console/Commands/Module/CompileModuleCommand.php create mode 100644 src/Console/Commands/Server/StartServerCommand.php create mode 100644 src/Console/VersaCLI.php create mode 100644 src/Logging/Log.php create mode 100644 src/Server/VersaServer.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b85a1c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +vendor/ +composer.lock +.idea/ +*.phar \ No newline at end of file diff --git a/bin/versa b/bin/versa new file mode 100644 index 0000000..25931d9 --- /dev/null +++ b/bin/versa @@ -0,0 +1,4 @@ +run(); \ No newline at end of file diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..df3ac1f --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "versadigitale/platform", + "description": "Anwendungsserver der modularen versa digitale Anwendungsplatform", + "type": "platform", + "license": "MIT", + "version": "1.0", + "autoload": { + "psr-4": { + "VersaDigitale\\Platform\\": "src/" + } + }, + "authors": [ + { + "name": "Elias Kleppinger", + "email": "e.kleppinger@buero-digitale.de" + } + ], + "require": { + "symfony/console": "^7.1", + "react/http": "^3@dev", + "react/async": "^3@dev", + "secondtruth/phar-compiler": "^1.2" + } +} diff --git a/src/Console/Commands/Development/CompilePlatformCommand.php b/src/Console/Commands/Development/CompilePlatformCommand.php new file mode 100644 index 0000000..aa6269c --- /dev/null +++ b/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/src/Console/Commands/Module/CompileModuleCommand.php b/src/Console/Commands/Module/CompileModuleCommand.php new file mode 100644 index 0000000..70a46a9 --- /dev/null +++ b/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/src/Console/Commands/Server/StartServerCommand.php b/src/Console/Commands/Server/StartServerCommand.php new file mode 100644 index 0000000..a3e844a --- /dev/null +++ b/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/src/Console/VersaCLI.php b/src/Console/VersaCLI.php new file mode 100644 index 0000000..fd996d5 --- /dev/null +++ b/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/src/Logging/Log.php b/src/Logging/Log.php new file mode 100644 index 0000000..7b72a0b --- /dev/null +++ b/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/src/Server/VersaServer.php b/src/Server/VersaServer.php new file mode 100644 index 0000000..1cbef46 --- /dev/null +++ b/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