diff --git a/src/Exception.php b/src/Exception.php index 5a2ea5c..455419b 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -6,6 +6,6 @@ class Exception extends \Exception { public static function create(string $error, array $context, \Exception $previous = null): Exception { - return new static(vsprintf($error, $context), 0, $previous); + return new self(vsprintf($error, $context), 0, $previous); } } diff --git a/src/Server.php b/src/Server.php index 9d3464c..2d6e487 100644 --- a/src/Server.php +++ b/src/Server.php @@ -167,7 +167,7 @@ private function handle(string $method, string $path, $contents, $request): Resp if ($method === 'HEAD') { $response->getBody()->rewind(); $response->getBody()->write(''); - $response = $response->withStatus("204"); // CHECKME: nextcloud will remove the updates-via header - any objections to give the 'HEAD' request a 'no content' response type? + $response = $response->withStatus(204); // CHECKME: nextcloud will remove the updates-via header - any objections to give the 'HEAD' request a 'no content' response type? if ($this->pubsub) { $response = $response->withHeader("updates-via", $this->pubsub); } @@ -177,7 +177,7 @@ private function handle(string $method, string $path, $contents, $request): Resp case 'OPTIONS': $response = $response ->withHeader('Vary', 'Accept') - ->withStatus('204') + ->withStatus(204) ; break; @@ -204,7 +204,7 @@ private function handle(string $method, string $path, $contents, $request): Resp $mimetype = self::MIME_TYPE_DIRECTORY; } if ($pathExists === true) { - if ($mimetype === self::MIME_TYPE_DIRECTORY) { + if (isset($mimetype) && $mimetype === self::MIME_TYPE_DIRECTORY) { $contentType= explode(";", $request->getHeaderLine("Content-Type"))[0]; $slug = $request->getHeaderLine("Slug"); if ($slug) { @@ -360,7 +360,7 @@ private function handleCreateRequest(Response $response, string $path, $contents } else { $success = false; - set_error_handler(static function($severity, $message, $filename, $line) { + set_error_handler(static function ($severity, $message, $filename, $line) { throw new \ErrorException($message, 0, $severity, $filename, $line); }); @@ -538,7 +538,7 @@ private function handleReadRequest(Response $response, string $path, $contents, $response->getBody()->write($contents); $response = $response->withHeader("Content-type", "text/turtle"); $response = $response->withStatus(200); - } else if ($filesystem->has($path) === false) { + } elseif ($filesystem->has($path) === false) { $message = vsprintf(self::ERROR_PATH_DOES_NOT_EXIST, [$path]); $response->getBody()->write($message); $response = $response->withStatus(404); diff --git a/src/example.php b/src/example.php index 0b6b3ee..2c8a5bc 100644 --- a/src/example.php +++ b/src/example.php @@ -66,7 +66,10 @@ $response = $server->respondToRequest($request); } elseif ($target === 'GET/') { - $response->getBody()->write(getHomepage()); + $fileHandle = fopen(__FILE__, 'rb'); + fseek($fileHandle, __COMPILER_HALT_OFFSET__); + $homepage = stream_get_contents($fileHandle); + $response->getBody()->write($homepage); } else { $response = $response->withStatus(404); $response->getBody()->write("
Path '$path' does not exist.
"); @@ -85,18 +88,9 @@ } } -echo (string) $response->getBody(); +echo (string) $response->getBody(); exit; -function getHomepage() : string -{ - $fileHandle = fopen(__FILE__, 'rb'); - - fseek($fileHandle, __COMPILER_HALT_OFFSET__); - - return stream_get_contents($fileHandle); -} - __halt_compiler();