From 4d45cc64499de2de6f758ff7c6f33d1fdd06f73e Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 19 Dec 2023 01:08:06 +0100 Subject: add PhpServer --- src/Server/RequestHandlers/PhpServer.php | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/Server/RequestHandlers/PhpServer.php (limited to 'src/Server/RequestHandlers') diff --git a/src/Server/RequestHandlers/PhpServer.php b/src/Server/RequestHandlers/PhpServer.php new file mode 100644 index 0000000..5447f72 --- /dev/null +++ b/src/Server/RequestHandlers/PhpServer.php @@ -0,0 +1,45 @@ +getPath()), '/'); + $filePath = $this->documentRoot . $requestPath; + + $documentPath = $filePath; + if (! is_file($documentPath)) { + $documentPath = $filePath . '/' . $this->indexFile; + } + + if (is_file($documentPath) && str_ends_with($documentPath, '.php')) { + ob_start(); + try { + include $documentPath; + } catch (\Throwable $exception) { + echo <<setBody($content); + $response->setStatusCode(Status::SUCCESS); + $response->setMeta('text/gemini; charset=utf-8'); + } else { + return parent::__invoke($response, $request); + } + + return $response; + } +} -- cgit v1.2.3