summaryrefslogtreecommitdiff
path: root/src/Client.php
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-11-12 11:16:56 +0100
committerDaniel Weipert <code@drogueronin.de>2023-11-20 17:30:04 +0100
commit6df3d321d9b67c4541f50158b087d37c4b22e886 (patch)
tree06031988bb4b957b76f051af366ced448a48545f /src/Client.php
initial commit
Diffstat (limited to 'src/Client.php')
-rw-r--r--src/Client.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Client.php b/src/Client.php
new file mode 100644
index 0000000..255e29f
--- /dev/null
+++ b/src/Client.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace GeminiFoundation;
+
+use GeminiFoundation\Response;
+
+class Client
+{
+ protected string $baseUrl;
+
+ public function __construct($baseUrl)
+ {
+ $this->baseUrl = $baseUrl;
+ }
+
+ public function request($url): Response
+ {
+ $context = stream_context_create(options: [
+ 'ssl' => [
+ 'verify_peer' => false,
+ ],
+ ]);
+
+ $connection = stream_socket_client(
+ address: "tls://{$this->baseUrl}:1965",
+ context: $context
+ );
+
+ fwrite($connection, "gemini://{$this->baseUrl}{$url}");
+ $responseString = '';
+ while (!feof($connection)) {
+ $responseString .= fgets($connection, 1024);
+ }
+ fclose($connection);
+
+ $response = Response::fromString($responseString);
+
+ return $response;
+ }
+}